mirror of
https://github.com/jneug/adventofcode.git
synced 2026-04-14 06:43:33 +02:00
28 lines
501 B
Python
28 lines
501 B
Python
input = []
|
|
with open('day8_input.txt', 'r') as f:
|
|
for line in f.readlines():
|
|
cmd,param = line.strip().split()
|
|
input.append((cmd, int(param)))
|
|
|
|
|
|
idx = 0
|
|
acc = 0
|
|
visited = []
|
|
running = True
|
|
while running:
|
|
if idx >= len(input):
|
|
break
|
|
elif idx in visited:
|
|
break
|
|
|
|
cmd,param = input[idx]
|
|
visited.append(idx)
|
|
if cmd == 'acc':
|
|
acc += param
|
|
idx += 1
|
|
elif cmd == 'jmp':
|
|
idx += param
|
|
else: # nop
|
|
idx += 1
|
|
|
|
print(acc) |