-
Notifications
You must be signed in to change notification settings - Fork 1
/
day2.py
49 lines (39 loc) · 1014 Bytes
/
day2.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
44
45
46
47
48
49
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)
prog[1] = 12
prog[2] = 2
prog.run()
return prog[0]
def part2(input):
for noun in range(100):
for verb in range(100):
prog = Intcode(input)
prog[1] = noun
prog[2] = verb
prog.run()
if prog[0] == 19690720:
return 100 * noun + verb
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))