aoc2020/08/2.py
2020-12-08 22:10:59 +00:00

38 lines
705 B
Python

instructions = [l.split(" ") for l in open("input_modified", "r").read().split("\n") if l]
instructions = [(operation, int(argument)) for (operation, argument) in instructions]
pc = 0
ac = 0
operations = {}
def operation(op):
def wrap(func):
operations[op] = func
return wrap
@operation("acc")
def acc(p):
global pc
global ac
ac += p
pc += 1
@operation("jmp")
def jmp(p):
global pc
pc += p
@operation("nop")
def nop(p):
global pc
if(pc + p > len(instructions)):
print(pc, "NOP COULD END")
pc += 1
while pc < len(instructions):
(opcode, p) = instructions[pc]
print(pc, ac, opcode, p)
op = operations[opcode]
op(p)
print(ac)