Day 10 template

This commit is contained in:
Jonas Neugebauer 2020-12-17 20:52:27 +01:00
parent 0f6ce4831c
commit bb8f6e1e8a
2 changed files with 133 additions and 0 deletions

37
2020/day10_1.py Normal file
View File

@ -0,0 +1,37 @@
from pprint import pprint
input = []
with open('day9_input.txt', 'r') as f:
for line in f.readlines():
input.append(int(line.strip()))
# prepare prefix cache
prefix = 25
cache = []
for i in range(prefix-1):
cache.append([])
for j in range(prefix-i-1):
cache[i].append(input[i]+input[i+j+1])
def check_val(cache, val):
for c in cache:
if val in c:
return True
return False
# start checking
err = None
for i in range(len(input)-prefix):
val = input[i+prefix]
if check_val(cache, val):
cache = cache[1:]
for j in range(prefix-2):
cache[j].append(input[i+j+1]+val)
cache.append([input[i+prefix-1]+val])
else:
err = i+prefix
break
print(err)
print(input[err-25:err])
print(input[err])

96
2020/day10_input.txt Normal file
View File

@ -0,0 +1,96 @@
70
102
148
9
99
63
40
52
91
39
55
28
54
22
95
61
118
35
14
21
129
82
137
45
7
87
81
25
3
108
41
11
145
18
65
80
115
29
136
42
97
104
117
141
62
121
23
96
24
128
48
1
112
8
34
144
134
116
58
147
51
84
17
126
64
68
135
10
77
105
127
73
111
90
16
103
109
98
146
123
130
69
133
110
30
122
15
74
33
38
83
92
2
53
140
4