mirror of
https://github.com/bertptrs/adventofcode.git
synced 2025-12-25 21:00:31 +01:00
Add minimal day 25 runner
This commit is contained in:
55
2019/aoc2019/day25.py
Normal file
55
2019/aoc2019/day25.py
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
from typing import TextIO
|
||||||
|
|
||||||
|
from aoc2019.intcode import read_program, Computer
|
||||||
|
|
||||||
|
|
||||||
|
def print_output(computer: Computer):
|
||||||
|
output = ""
|
||||||
|
|
||||||
|
while len(computer.output):
|
||||||
|
output += chr(computer.get_output())
|
||||||
|
|
||||||
|
print(output, end='')
|
||||||
|
|
||||||
|
|
||||||
|
def load_save(save, computer: Computer):
|
||||||
|
computer.pointer, computer.relative_base, computer.program = save
|
||||||
|
|
||||||
|
|
||||||
|
def create_save(computer: Computer):
|
||||||
|
return computer.pointer, computer.relative_base, computer.program.copy()
|
||||||
|
|
||||||
|
|
||||||
|
def part1(data: TextIO):
|
||||||
|
print("This day must use a file as input as it requires the stdin for other things.")
|
||||||
|
|
||||||
|
computer = Computer(read_program(data))
|
||||||
|
|
||||||
|
saves = {}
|
||||||
|
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
computer.run()
|
||||||
|
print_output(computer)
|
||||||
|
|
||||||
|
print("detected a death, loading auto save...")
|
||||||
|
load_save(saves['auto'], computer)
|
||||||
|
print("Command?")
|
||||||
|
except IndexError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
print_output(computer)
|
||||||
|
|
||||||
|
saves['auto'] = create_save(computer)
|
||||||
|
|
||||||
|
command = input().strip()
|
||||||
|
|
||||||
|
if command == "exit":
|
||||||
|
return
|
||||||
|
# TODO: add manual save states.
|
||||||
|
|
||||||
|
for c in command:
|
||||||
|
computer.send_input(ord(c))
|
||||||
|
|
||||||
|
computer.send_input(10) # manually send newline
|
||||||
|
|
||||||
1
2019/inputs/25.txt
Normal file
1
2019/inputs/25.txt
Normal file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user