-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path02-2.py
More file actions
executable file
·51 lines (44 loc) · 1.25 KB
/
Copy path02-2.py
File metadata and controls
executable file
·51 lines (44 loc) · 1.25 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env python
import input_day_two
def opcodeCalc(position, input_list):
pos1 = input_list[position]
pos2 = input_list[position + 1]
pos3 = input_list[position + 2]
pos4 = input_list[position + 3]
if pos1 == 1:
res = input_list[pos2] + input_list[pos3]
elif pos1 == 2:
res = input_list[pos2] * input_list[pos3]
elif pos1 == 99:
return input_list[0]
else:
exit("[Function opcodeCalc] Invalid method {}. Position: {}".format(pos1, position))
input_list[pos4] = res
return input_list
def opcode(input_list):
input_list = input_list
for i in range(0, 10000, 4):
input_list = opcodeCalc(i, input_list)
if type(input_list) == int:
break
return input_list
if __name__ == "__main__":
original_list = input_day_two.input.copy()
input = input_day_two.input.copy()
noun = 1
verb = 1
result = 0
while result != 19690720:
input = original_list.copy()
verb+=1
input[1] = noun
input[2] = verb
try:
result = opcode(input)
except IndexError:
noun += 1
verb = 0
if result > 19690720:
noun += 1
verb = 0
print(100 * noun + verb)