Files
python-aoc-2020/day08/part1.py
Sebastian Seedorf 525c2c91e6 Day 8
2020-12-08 15:22:23 +01:00

25 lines
523 B
Python

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