mirror of
https://github.com/bertptrs/adventofcode.git
synced 2025-12-25 21:00:31 +01:00
Implement 2019 day 2
Start of the intcode madness
This commit is contained in:
33
2019/aoc2019/day02.py
Normal file
33
2019/aoc2019/day02.py
Normal 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')
|
||||
Reference in New Issue
Block a user