day8
This commit is contained in:
39
day8/day8.py
Normal file
39
day8/day8.py
Normal file
@@ -0,0 +1,39 @@
|
||||
def part1():
|
||||
file = open("input.txt")
|
||||
|
||||
instructions = []
|
||||
|
||||
for line in file:
|
||||
args = line.strip().split(" ")
|
||||
instructions.append({
|
||||
'op': args[0],
|
||||
'arg': int(args[1]),
|
||||
'visited': False
|
||||
})
|
||||
|
||||
finger = 0
|
||||
acc = 0
|
||||
|
||||
while not instructions[finger]['visited']:
|
||||
op = instructions[finger]['op']
|
||||
arg = instructions[finger]['arg']
|
||||
instructions[finger]['visited'] = True
|
||||
|
||||
if op == 'nop':
|
||||
finger += 1
|
||||
continue
|
||||
elif op == 'jmp':
|
||||
finger += arg
|
||||
elif op == 'acc':
|
||||
acc += arg
|
||||
finger += 1
|
||||
|
||||
print("Part 1: %d" % acc)
|
||||
|
||||
def part2():
|
||||
print("Part 2: %d")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
part1()
|
||||
part2()
|
||||
Reference in New Issue
Block a user