-
Notifications
You must be signed in to change notification settings - Fork 1
/
23.py
39 lines (34 loc) · 1 KB
/
23.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
# --- Day 23: Opening the Turing Lock ---
def day_23(instructions, registers):
inst = []
for line in instructions:
inst.append(line.replace("\n", "").split(" "))
counter = 0
while counter < len(inst):
x = inst[counter]
if x[0] == "hlf":
registers[x[1]] = registers[x[1]] / 2
counter += 1
elif x[0] == "tpl":
registers[x[1]] = registers[x[1]] * 3
counter += 1
elif x[0] == "inc":
registers[x[1]] = registers[x[1]] + 1
counter += 1
elif x[0] == "jmp":
counter += int(x[1])
elif x[0] == "jie":
if registers[x[1].replace(",", "")] % 2 == 0:
counter += int(x[2])
else:
counter += 1
elif x[0] == "jio":
if registers[x[1].replace(",", "")] == 1:
counter += int(x[2])
else:
counter += 1
return registers["b"]
with open("input/23.txt") as instructions:
print(day_23(instructions, {"a": 0, "b": 0}))
with open("input/23.txt") as instructions:
print(day_23(instructions, {"a": 1, "b": 0}))