diff options
| author | Gustav Sörnäs <gusso230@student.liu.se> | 2019-12-21 07:45:12 +0100 |
|---|---|---|
| committer | Gustav Sörnäs <gusso230@student.liu.se> | 2019-12-21 07:45:12 +0100 |
| commit | 6e2250450329953567a6aa552d1b6990ee0188cb (patch) | |
| tree | 7682ed57639b9e4116958d286db524e37daa969f /19/py/d21.py | |
| parent | 756cbfd3f6b28db2ac636f5dffeee49f05f51f61 (diff) | |
| download | aoc-6e2250450329953567a6aa552d1b6990ee0188cb.tar.gz | |
Day 21 py
Diffstat (limited to '19/py/d21.py')
| -rw-r--r-- | 19/py/d21.py | 36 |
1 files changed, 36 insertions, 0 deletions
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)) |
