summaryrefslogtreecommitdiffstats
path: root/19/py/d09.py
blob: ada6763acb1284644bbe2bd6b892693366dd38ce (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
import intcode

def do(input, code):
    program = [int(x) for x in input.split(",")]
    c = intcode.Computer(program)
    c.input = code
    output = []
    while True:
        c.step()
        #print(c.relative_base, c.pointer, c.memory)
        if c.SIG_HALT:
            break
        if c.output is not None:
            output.append(c.output)
            c.output = None
    return output

def pt1(input):
    return do(input[0], 1)

def pt2(input):
    return do(input[0], 2)

if __name__ == "__main__":
    input = open("../input/09", "r").readlines()
    print(pt1(input))
    print(pt2(input))