-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path9.py
50 lines (47 loc) · 1.33 KB
/
9.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
40
41
42
43
44
45
46
47
48
49
50
import os
fileName = "9.txt"
preamble = 25
part1Num = -1
part1Index = -1
with open(fileName) as file:
numbers = file.readlines()
for i in range(len(numbers)):
numbers[i] = int(numbers[i])
i = preamble
isValid = True
while i < len(numbers) and isValid:
checkValue = int(numbers[i])
isValid = False
for j in range(preamble):
for k in range(preamble):
if j != k and checkValue == (int(numbers[i - j - 1]) + int(numbers[i - k - 1])):
isValid = True
break
k = k + 1
if isValid:
break
j = j + 1
if isValid:
i = i + 1
print(numbers[i], i, len(numbers))
part1Num = int(numbers[i])
part1Index = i
#part 2
indexMin = -1
indexMax = -1
for startIndex in range(part1Index):
sum = 0
for i in range(part1Index - startIndex):
if sum < part1Num:
sum = sum + int(numbers[startIndex + i])
else:
break
i = i + 1
if sum == part1Num:
indexMin = startIndex
indexMax = startIndex + i
break
startIndex = startIndex + 1
newRange = numbers[indexMin:indexMax]
newRange.sort()
print(newRange[0] + newRange[-1])