-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path02.py
36 lines (30 loc) · 860 Bytes
/
02.py
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
from lib import *
input = read_input(2019, 2)
(*mem,) = map(int, input.strip().split(","))
i = 0
mem[1] = 12
mem[2] = 2
while i < len(mem):
if mem[i] == 99:
break
elif mem[i] == 1:
mem[mem[i + 3]] = mem[mem[i + 1]] + mem[mem[i + 2]]
elif mem[i] == 2:
mem[mem[i + 3]] = mem[mem[i + 1]] * mem[mem[i + 2]]
i += 4
print(mem[0])
(*mem,) = map(int, input.strip().split(","))
def simulate(a, b, mem):
i = 0
mem[1] = a
mem[2] = b
while i < len(mem):
if mem[i] == 99:
break
elif mem[i] == 1:
mem[mem[i + 3]] = mem[mem[i + 1]] + mem[mem[i + 2]]
elif mem[i] == 2:
mem[mem[i + 3]] = mem[mem[i + 1]] * mem[mem[i + 2]]
i += 4
return mem[0]
print(*[a * 100 + b for a in range(100) for b in range(100) if simulate(a, b, mem[:]) == 19690720])