-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdayNine.py
39 lines (36 loc) · 941 Bytes
/
dayNine.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
from collections import deque
values = []
with open("dayNine.txt") as file:
for line in file:
num = line.rstrip()
values.append(int(num))
preambles = deque(values[:25])
def calculate_sums(preambles):
sums = set()
for i in range(len(preambles)):
for j in range(len(preambles)):
if i != j:
sums.add(preambles[i]+preambles[j])
return sums
curr_index = 25
for i in range(25, len(values)):
sums = calculate_sums(preambles)
if values[i] not in sums:
print(values[i])
break
preambles.popleft()
preambles.append(values[curr_index])
curr_index += 1
# q2
i = -1
j = 0
tot = 0
while j < len(values):
tot += values[j]
while tot > 776203571:
i += 1
tot -= values[i]
if tot == 776203571:
print(max(values[i+1:j+1]) + min(values[i+1:j+1])) # starts at i+1 to j as i has been removed
break
j += 1