-
Notifications
You must be signed in to change notification settings - Fork 140
Expand file tree
/
Copy pathd2.py
More file actions
32 lines (29 loc) · 730 Bytes
/
d2.py
File metadata and controls
32 lines (29 loc) · 730 Bytes
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
with open('./input.txt') as f:
program = [int(x) for x in f.read().split(',')]
def run(program):
program = program[:]
i = 0
while True:
operation = program[i:i+4]
op = operation[0]
if op == 99:
return program[0]
_ , a, b, to = operation
if op == 1:
program[to] = program[a] + program[b]
elif op == 2:
program[to] = program[a] * program[b]
i += 4
# p1
p1 = program[:]
p1[1] = 12
p1[2] = 2
print(run(p1))
# p2
for x in range(100):
for y in range(100):
p2 = program[:]
p2[1] = x
p2[2] = y
if run(p2) == 19690720: # replace this with the number you're given
print(100*x + y)