lines = list(map(lambda y: (y[0], int(y[1])), (x.strip().split() for x in open("input.txt")))) length = len(lines) executed = set() pos = 0 acc = 0 print(lines) while True: cmd, val = lines[pos] executed.add(pos) if cmd == 'nop': pos += 1 elif cmd == 'acc': acc += val pos += 1 elif cmd == 'jmp': pos += val if pos in executed: print('loop detected, current acc:', acc) break if pos >= length: print('out of bounds:', pos) break