-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathday9.py
43 lines (34 loc) · 892 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
40
41
42
43
from collections import defaultdict
import itertools
import math
from hashlib import md5
import msvcrt
#import numpy as np
import os.path
import re
import sys
from intcode import Intcode
def get_input(filename=None):
if not filename:
filename = os.path.splitext(os.path.basename(__file__))[0] + '.txt'
with open(filename) as fp:
input = fp.read().rstrip()
return list(map(int, input.split(',')))
def part1(input):
prog = Intcode(input, [1])
prog.run()
print(prog.output)
return prog.output[-1]
def part2(input):
prog = Intcode(input, [2])
prog.run()
print(prog.output)
return prog.output[-1]
if __name__ == '__main__':
from argparse import ArgumentParser
parser = ArgumentParser()
parser.add_argument('input', nargs='?', metavar='input.txt')
args = parser.parse_args()
input = get_input(args.input)
print(part1(input))
print(part2(input))