summaryrefslogtreecommitdiff
path: root/2019/2.py
blob: 9833888a0385b0c0a317a4d080774909616d3c54 (plain)
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
#!/usr/bin/env python3
import sys

with open("2.in") as f:
    arr = [int(x) for x in f.read().strip().split(",")]

origarr = arr[:]

def run(n,v):
    arr = origarr[:]
    arr[1] = n
    arr[2] = v

    i = 0
    while arr[i] != 99:
        C,a,b,c = arr[i:i+4]
        if C == 1:
            arr[c] = arr[a] + arr[b]
        elif C == 2:
            arr[c] = arr[a] * arr[b]
        else:
            assert False
        i += 4

    return arr[0]

print(run(12,2))

for n in range(100):
    for v in range(100):
        if run(n,v) == 19690720:
            print(100 * n + v)
            sys.exit(0)