mirror of
https://github.com/jneug/adventofcode.git
synced 2026-04-14 06:43:33 +02:00
Day 8
This commit is contained in:
28
2020/day8_1.py
Normal file
28
2020/day8_1.py
Normal file
@@ -0,0 +1,28 @@
|
||||
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)
|
||||
Reference in New Issue
Block a user