-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathday9.py
39 lines (29 loc) · 898 Bytes
/
day9.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
37
38
39
from typing import List
from Computer import Computer, OutputInterrupt
def parse_input(filename: str) -> List[int]:
return [int(d) for d in open(filename).read().strip().split(',')]
def part1(code: List[int]) -> int:
computer = Computer(code)
computer.inputs.append(1)
while not computer.done:
try:
computer.run()
except OutputInterrupt:
return computer.outputs[-1]
return 0
def part2(code: List[int]) -> int:
computer = Computer(code)
computer.inputs.append(2)
while not computer.done:
try:
computer.run()
except OutputInterrupt:
return computer.outputs[-1]
return 0
def main():
code = parse_input('input/day9.txt')
print(f'Part 1: {part1(code)}')
code = parse_input('input/day9.txt')
print(f'Part 2: {part2(code)}')
if __name__ == "__main__":
main()