Implement 2019 day 2

Start of the intcode madness
This commit is contained in:
2021-01-23 17:05:10 +01:00
parent 07e869c497
commit 930d86404d
3 changed files with 112 additions and 0 deletions

33
2019/aoc2019/day02.py Normal file
View File

@@ -0,0 +1,33 @@
from typing import TextIO
from aoc2019.intcode import read_program, Computer
def part1(data: TextIO) -> int:
program = read_program(data)
program[1] = 12
program[2] = 2
computer = Computer(program)
computer.run()
return computer[0]
def part2(data: TextIO) -> int:
program = read_program(data)
for verb in range(100):
for noun in range(100):
computer = Computer(program.copy())
computer[1] = noun
computer[2] = verb
computer.run()
if computer[0] == 19690720:
return 100 * noun + verb
raise ValueError('Did not find valid combination')