#!/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