mirror of
https://github.com/bertptrs/adventofcode.git
synced 2025-12-27 13:50:32 +01:00
Implement 2019 day 9
This commit is contained in:
25
2019/aoc2019/day09.py
Normal file
25
2019/aoc2019/day09.py
Normal file
@@ -0,0 +1,25 @@
|
||||
import sys
|
||||
from typing import TextIO
|
||||
|
||||
from aoc2019.intcode import read_program, Computer
|
||||
|
||||
|
||||
def run_machine(data: TextIO, initializer: int) -> int:
|
||||
program = read_program(data)
|
||||
computer = Computer(program)
|
||||
computer.input.append(initializer)
|
||||
|
||||
computer.run()
|
||||
|
||||
if len(computer.output) > 1:
|
||||
sys.exit(computer.output)
|
||||
else:
|
||||
return computer.output.pop()
|
||||
|
||||
|
||||
def part1(data: TextIO) -> int:
|
||||
return run_machine(data, 1)
|
||||
|
||||
|
||||
def part2(data: TextIO) -> int:
|
||||
return run_machine(data, 2)
|
||||
Reference in New Issue
Block a user