-
Notifications
You must be signed in to change notification settings - Fork 0
/
AoC23.py
33 lines (32 loc) · 1.19 KB
/
AoC23.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
code = [i.strip() for i in open("input.txt").readlines()]
pos = 0
reg = {'a': 12, 'b': 0, 'c': 0, 'd': 0}
while pos < len(code):
ops = code[pos].split(' ')
ops1 = reg[ops[1]] if ops[1].isalpha() else int(ops[1])
if ops[0] == "cpy":
if ops[2].isalpha(): reg[ops[2]] = ops1
elif ops[0] == "inc":
if ops[1].isalpha(): reg[ops[1]] += 1
elif ops[0] == "dec":
if ops[1].isalpha(): reg[ops[1]] -= 1
elif ops[0] == "mul":
reg[ops[3]] += reg[ops[2]] * reg[ops[1]]
reg[ops[2]] = 0
reg[ops[1]] = 0
elif ops[0] == "tgl":
if pos+ops1 in range(0, len(code)):
tglops = code[pos+ops1].split(' ')
if tglops[0] in {"dec", "tgl"}:
code[pos+ops1] = "inc "+ ' '.join(tglops[1:])
if tglops[0] == "inc":
code[pos+ops1] = "dec "+ ' '.join(tglops[1:])
if tglops[0] == "jnz":
code[pos+ops1] = "cpy "+ ' '.join(tglops[1:])
if tglops[0] == "cpy":
code[pos+ops1] = "jnz "+ ' '.join(tglops[1:])
if ops[0] == "jnz" and ops1 != 0:
pos += reg[ops[2]] if ops[2].isalpha() else int(ops[2])
else:
pos += 1
print(reg)