Add minimal day 25 runner

This commit is contained in:
2021-10-16 17:46:55 +02:00
parent dbf6b2eb17
commit 71f54bac6b
2 changed files with 56 additions and 0 deletions

55
2019/aoc2019/day25.py Normal file
View 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

File diff suppressed because one or more lines are too long