-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path12-2.py
More file actions
33 lines (26 loc) · 733 Bytes
/
12-2.py
File metadata and controls
33 lines (26 loc) · 733 Bytes
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
from collections import defaultdict
reg = defaultdict(int)
reg['c'] = 1
data = open('12.txt').read().split('\n')
i = 0
while i < len(data):
line = data[i]
if line.startswith('cpy'):
args = line.split()[1:]
x = reg[args[0]] if not args[0].isdigit() else int(args[0])
y = args[1]
reg[y] = x
elif line.startswith('inc'):
x = line.split(' ')[-1]
reg[x] += 1
elif line.startswith('dec'):
x = line.split(' ')[-1]
reg[x] -= 1
elif line.startswith('jnz'):
args = line.split()[1:]
x = reg[args[0]] if not args[0].isdigit() else int(args[0])
y = int(args[1])
if x != 0:
i += y - 1
i += 1
print(reg['a'])