-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathday_02a.py
34 lines (27 loc) · 814 Bytes
/
day_02a.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
#!/usr/bin/python3
import sys
def main():
# Get input
file_name = "../input/day_02_input"
if len(sys.argv) > 1:
file_name = sys.argv[1]
file = open(file_name)
program = list(map(int, file.readline().split(",")))
# Modify program according to puzzle instructions
program[1] = 12
program[2] = 2
# Solve
index = 0
while program[index] != 99:
if program[index] == 1:
program[program[index + 3]] = (
program[program[index + 1]] + program[program[index + 2]]
)
elif program[index] == 2:
program[program[index + 3]] = (
program[program[index + 1]] * program[program[index + 2]]
)
index = index + 4
print(program[0])
if __name__ == "__main__":
main()