-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path23.py
56 lines (49 loc) · 1.28 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
from lib import *
input = read_input(2015, 23)
program = input.splitlines()
pc = 0
registers = {"a": 0, "b": 0}
while pc < len(program):
cmd, args = program[pc].split(maxsplit=1)
args = args.split(", ")
if cmd == "hlf":
registers[args[0]] //= 2
pc += 1
elif cmd == "tpl":
registers[args[0]] *= 3
pc += 1
elif cmd == "inc":
registers[args[0]] += 1
pc += 1
elif cmd == "jmp":
pc += int(args[0])
elif cmd == "jie":
pc += int(args[1]) if registers[args[0]] % 2 == 0 else 1
elif cmd == "jio":
pc += int(args[1]) if registers[args[0]] == 1 else 1
else:
break
print(registers["b"])
pc = 0
registers = {"a": 1, "b": 0}
while pc < len(program):
cmd, args = program[pc].split(maxsplit=1)
args = args.split(", ")
if cmd == "hlf":
registers[args[0]] //= 2
pc += 1
elif cmd == "tpl":
registers[args[0]] *= 3
pc += 1
elif cmd == "inc":
registers[args[0]] += 1
pc += 1
elif cmd == "jmp":
pc += int(args[0])
elif cmd == "jie":
pc += int(args[1]) if registers[args[0]] % 2 == 0 else 1
elif cmd == "jio":
pc += int(args[1]) if registers[args[0]] == 1 else 1
else:
break
print(registers["b"])