-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday9.py
More file actions
31 lines (26 loc) · 1.06 KB
/
day9.py
File metadata and controls
31 lines (26 loc) · 1.06 KB
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
import itertools as it
def findFlawedNumber(numbers, loadedSize=25):
previousNums = numbers[:loadedSize]
print(previousNums)
for x in range(loadedSize, len(numbers)):
anyTwoSum = [sum(combo) for combo in it.combinations(previousNums, 2)]
if numbers[x] in anyTwoSum:
previousNums = numbers[(x+1)-loadedSize:(x+1)]
else:
return numbers[x]
return None
def findContiguousNumbers(numbers, sumNum):
contiguousList = []
for x in range(len(numbers)):
for y in range(x, len(numbers)):
contiguousList.append(numbers[y])
if sum(contiguousList) == sumNum:
return contiguousList
elif sum(contiguousList) > sumNum:
del contiguousList[:]
break
inputNumbers = [int(line.strip()) for line in open('day9input.txt')]
flawedNumber = findFlawedNumber(inputNumbers)
print(flawedNumber)
contiguousNumbers = findContiguousNumbers(inputNumbers, flawedNumber)
print(min(contiguousNumbers) + max(contiguousNumbers))