2020 day 9

This commit is contained in:
Luke Hubmayer-Werner 2020-12-14 18:16:16 +10:30
parent 607ebd0f4d
commit e2b9ee38c2
2 changed files with 1025 additions and 0 deletions

25
2020/day09.py Normal file
View File

@ -0,0 +1,25 @@
import numpy as np
with open('input09', 'r') as file:
input = [int(l.strip()) for l in file.readlines()]
inp = np.array(input)
def find_deviant():
data = np.tile(inp, [25,1])
for i in range(25):
data[i,i+1:] += inp[:-i-1]
for i,num in enumerate(input[25:], 25):
if not (data[:, max(0, i-25):i] == num).any():
return num, i
num, i = find_deviant()
print(f'Part 1: first deviant at {i} - {num}')
def find_sumstreak(number):
inps = inp.cumsum()
for i in range(len(input)):
hits = (inps[i:]-inps[i]) == number
if hits.any():
return i+1, i+hits.argmax()+1 # Not entirely sure where the +1 snuck in but w/e
i, j = find_sumstreak(num)
print(f'Part 2: slice {i}:{j} - min+max = {inp[i:j].min()+inp[i:j].max()}')

1000
2020/input09 Normal file

File diff suppressed because it is too large Load Diff