This commit is contained in:
Dece 2019-12-21 22:04:47 +01:00
parent 8992b18382
commit 1c0ad51b60
3 changed files with 48 additions and 0 deletions

View file

@ -0,0 +1,6 @@
OR D J
NOT C T
AND T J
NOT A T
OR T J
WALK

20
2019/day21.py Normal file
View file

@ -0,0 +1,20 @@
import sys
from intcode import AIC
def main():
codes = AIC.parse_file("day21.txt")
ss = SSIC(codes, script=sys.stdin.read())
ss.run()
class SSIC(AIC):
def __init__(self, *args, script="", **kwargs):
super().__init__(*args, **kwargs)
self.input_text = script
if __name__ == "__main__":
main()

View file

@ -162,3 +162,25 @@ class Intcode(object):
def output_data(self, data):
print(">", data)
class AIC(Intcode):
"""ASCII-enabled Intcode interpreter."""
LN = ord("\n")
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.input_text = ""
def input_data(self):
data, self.input_text = self.input_text[0], self.input_text[1:]
return ord(data)
def output_data(self, data):
if data > 256:
self.handle_int_output(data)
else:
print(chr(data), end="")
def handle_int_output(self, i):
print(f"Int output: {i}.")