-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsolution.py
31 lines (28 loc) · 823 Bytes
/
solution.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
lines = []
registers = {}
with open("input", "r") as f:
for l in f: lines.append(l.strip().split(" "))
for l in lines: registers[l[1]] = 0
registers.pop('1', None)
pos = 0
sound = 0
while pos >= 0 and not pos >= len(lines):
l = lines[pos]
pos += 1
if x not in registers: x = int(l[1])
else: x = l[1]
if len(l) > 2:
if l[2] in registers: y = registers[l[2]]
else: y = int(l[2])
if l[0] == "snd": sound = registers[x]
elif l[0] == "set": registers[x] = y
elif l[0] == "add": registers[x] += y
elif l[0] == "mul": registers[x] *= y
elif l[0] == "mod": registers[x] %= y
elif l[0] == "rcv":
if x != 0:
print(sound)
break
elif l[0] == "jgz":
if x in registers: x = registers[x]
if x > 0: pos += y - 1