-
Notifications
You must be signed in to change notification settings - Fork 0
/
12.py
37 lines (28 loc) · 774 Bytes
/
12.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
from lib import *
input = read_input(2016, 12)
program = input.splitlines()
registers = {k: 0 for k in "abcd"}
def simulate():
pc = 0
while pc < len(program):
cmd, *args = program[pc].split()
x = registers[args[0]] if args[0] in registers else int(args[0])
if cmd == "cpy":
registers[args[1]] = x
pc += 1
elif cmd == "inc":
registers[args[0]] += 1
pc += 1
elif cmd == "dec":
registers[args[0]] -= 1
pc += 1
elif cmd == "jnz":
if x:
pc += int(args[1])
else:
pc += 1
return registers["a"]
print(simulate())
registers = {k: 0 for k in "abcd"}
registers["c"] = 1
print(simulate())