aoc/2019/02/02.py

31 lines
683 B
Python
Raw Permalink Normal View History

2020-12-11 21:16:01 +00:00
def process(program):
i = 0
while True:
opcode = program[i]
if opcode == 99:
break
elif opcode == 1:
program[program[i+3]] = program[program[i+1]] + program[program[i+2]]
elif opcode == 2:
program[program[i+3]] = program[program[i+1]] * program[program[i+2]]
else:
break
i += 4
return program[0]
def alarm(noun, verb):
with open("input.txt","r") as f:
program = [int(x) for x in f.read().split(',')]
program[1] = noun
program[2] = verb
return process(program)
def part2():
for noun in range(100):
for verb in range(1,100):
if alarm(noun, verb) == 19690720:
return 100 * noun + verb
part1 = alarm(12,2)
part2 = part2()
print(part1, part2)