-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday9.py
33 lines (26 loc) · 960 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
input_filename = __file__.split('.')[0] + ".input"
with open(input_filename) as f:
raw = f.read().strip().split('\n')
numbers = [int(x) for x in raw]
def _part1():
working_set = numbers[:25]
for number in numbers[25:]:
if any(a + b == number for a in working_set for b in working_set):
working_set.pop(0)
working_set.append(number)
continue
print(f"Number {number} breaks the pattern")
return number
invalid_number = _part1()
for start_line_no in range(len(numbers)):
working_total = 0
end_line_no = start_line_no + 2
working_total = sum(numbers[start_line_no:end_line_no])
while working_total < invalid_number:
end_line_no += 1
working_total = sum(numbers[start_line_no:end_line_no])
if working_total != invalid_number:
continue
print("We found it!")
parts = numbers[start_line_no:end_line_no]
print(min(parts) + max(parts))