adventofcode-2020/08/part1

31 lines
495 B
Plaintext
Raw Permalink Normal View History

2020-12-13 17:39:01 +01:00
#!/usr/bin/python3
from pprint import pprint
prog = []
acc = 0
ip = 0
with open("input") as fh:
for ln in fh:
op, arg = ln.split()
prog.append((op, int(arg)))
pprint(prog)
seen = set()
while True:
if ip in seen:
print(acc)
break;
seen.add(ip)
op = prog[ip][0]
arg = prog[ip][1]
print(acc, ip, op, arg)
if op == "acc":
acc += arg
ip += 1
elif op == "jmp":
ip += arg
elif op == "nop":
ip += 1