Day 8
This commit is contained in:
24
day08/part1.py
Normal file
24
day08/part1.py
Normal file
@@ -0,0 +1,24 @@
|
||||
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
|
||||
Reference in New Issue
Block a user