aoc2019/day02.py
2021-11-30 01:01:08 +01:00

34 lines
799 B
Python

from aoc import AOCDay
from typing import Any
from intcode import IntCode
class Day(AOCDay):
test_solutions_p1 = [100, 2, 2, 2, 30]
test_solutions_p2 = []
def part1(self) -> Any:
memory = self.getInputAsArraySplit(',', int)
memory[1] = 12
memory[2] = 2
comp = IntCode(memory)
comp.run()
return comp.memory[0]
def part2(self) -> Any:
init_memory = self.getInputAsArraySplit(",", int)
for x in range(100):
for y in range(100):
memory = init_memory.copy()
memory[1] = x
memory[2] = y
comp = IntCode(memory)
comp.run()
if comp.memory[0] == 19690720:
return 100 * x + y
return -1