-
Notifications
You must be signed in to change notification settings - Fork 0
/
p02.py
31 lines (23 loc) · 842 Bytes
/
p02.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
from aocd import data
target = 19690720
data = [int(code) for code in data.split(',')]
for noun in range(100):
for verb in range(100):
program = data.copy()
program[1] = noun
program[2] = verb
pointer = 0
while program[pointer] != 99:
input_a = program[pointer+1]
input_b = program[pointer+2]
output = program[pointer+3]
if program[pointer] == 1:
program[output] = program[input_a] + program[input_b]
elif program[pointer] == 2:
program[output] = program[input_a] * program[input_b]
pointer += 4
if program[0] == target:
print('Part 2:', 100 * noun + verb)
raise SystemExit
elif noun == 12 and verb == 2:
print('Part 1:', program[0])