-
Notifications
You must be signed in to change notification settings - Fork 0
/
Day12.py
44 lines (39 loc) · 1.06 KB
/
Day12.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import re
with open('Day12.in', 'r') as f:
data = f.readlines()
part_2 = True
if part_2:
registers = {"a": 0, "b": 0, "c": 1, "d": 0}
else:
registers = {"a": 0, "b": 0, "c": 0, "d": 0}
instructions = []
for line in data:
instructions.append(line.strip().split())
i = 0
while i < len(instructions):
instruction = instructions[i]
name = instruction[0]
args = instruction[1:]
#print("Executign %s" % instruction)
if name == "cpy":
val = None
try:
val = int(args[0])
except ValueError:
val = registers[args[0]]
registers[args[1]] = val
if (name == "inc" or name == "dec") and args[0] != "0":
#print("%s %s by 1" % (name, args[0]))
registers[args[0]] += 1 if name == "inc" else -1
#print(registers[args[0]])
if (name == "jnz"):
val = None
try:
val = int(args[0])
except ValueError:
val = registers[args[0]]
if val != 0:
i += int(args[1])
continue
i += 1
print(registers)