From 6e2250450329953567a6aa552d1b6990ee0188cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Sat, 21 Dec 2019 07:45:12 +0100 Subject: Day 21 py --- 19/py/d21.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 19/py/d21.py (limited to '19/py/d21.py') diff --git a/19/py/d21.py b/19/py/d21.py new file mode 100644 index 0000000..2e39563 --- /dev/null +++ b/19/py/d21.py @@ -0,0 +1,36 @@ +import intcode + +f = open("../input/21", "r").readlines() + +c = intcode.Computer([int(x) for x in f[0].split(",")], ascii=True) +output = [] + +def ascii_draw(a): + s = "" + for c in a: + if c == 10: + s += "\n" + elif c < 128: + s += chr(c) + else: + print("[INVALID ASCII]", c) + return s + +while not c.SIG_HALT: + c.step() + if c.SIG_INPUT: + # flush output + print(ascii_draw(output)) + output = [] + if len(output) > 0: + output = [] + while True: + s = input() + if s.upper() == "END": + break + c.queue_ascii(s.upper()) + if c.SIG_OUTPUT: + output.append(c.output) + c.output = None +print(output) +print(ascii_draw(output)) -- cgit v1.2.1