This commit is contained in:
2020-12-09 21:58:36 +01:00
parent dc12f63058
commit d552142019
6 changed files with 2045 additions and 0 deletions

53
day09/module.py Normal file
View File

@@ -0,0 +1,53 @@
from aoc.input import get_input
import copy
import itertools
import time
import collections
import re
from aoc.partselector import part_one, part_two
import functools
def pw(line):
return int(line.strip())
def p1():
inp = get_input(pw)
for i in range(25, len(inp)):
possible_values = set()
for sample in itertools.combinations(inp[i-25:i], 2):
possible_values.add(sum(sample))
if inp[i] not in possible_values:
print (inp[i])
return inp
return inp
def p2(inp):
l = 1398413738
i = 636
d = {}
for j in range(2, 25):
possible_values = set()
for sample in range(1,636):
possible_values.add(sum(inp[sample: sample+j]))
d [sum(inp[sample: sample+j])] = inp[sample: sample+j]
if l in possible_values:
print(min(d[l]) + max(d[l]))
return (min(d[l]) + max(d[l]))
return 0
if part_one():
start = time.time()
result1 = p1()
print(round(1000*(time.time() - start), 2), 'ms')
if part_two():
start = time.time()
p2(result1)
print(round(1000*(time.time() - start), 2), 'ms')