summaryrefslogtreecommitdiffstats
path: root/19/py/d21.py
blob: 3b2e12305e605608241d7bcefcab9152d419a177 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# program and idea for part 1:
# jump if any tile of the first three aren't ground and the fourth is ground
# J = (not A or not B or not C) and D
# (dm) <=> J = not (A and B and C) and D
# or A T
# and B T
# and C T
# not T J
# and D J
# walk

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))