File tree 3 files changed +1070
-0
lines changed
3 files changed +1070
-0
lines changed Original file line number Diff line number Diff line change
1
+ 35
2
+ 20
3
+ 15
4
+ 25
5
+ 47
6
+ 40
7
+ 62
8
+ 55
9
+ 65
10
+ 95
11
+ 102
12
+ 117
13
+ 150
14
+ 182
15
+ 127
16
+ 219
17
+ 299
18
+ 277
19
+ 309
20
+ 576
Original file line number Diff line number Diff line change
1
+ import os
2
+
3
+ fileName = "9.txt"
4
+ preamble = 25
5
+ part1Num = - 1
6
+ part1Index = - 1
7
+ with open (fileName ) as file :
8
+ numbers = file .readlines ()
9
+ for i in range (len (numbers )):
10
+ numbers [i ] = int (numbers [i ])
11
+ i = preamble
12
+ isValid = True
13
+ while i < len (numbers ) and isValid :
14
+ checkValue = int (numbers [i ])
15
+ isValid = False
16
+ for j in range (preamble ):
17
+ for k in range (preamble ):
18
+ if j != k and checkValue == (int (numbers [i - j - 1 ]) + int (numbers [i - k - 1 ])):
19
+ isValid = True
20
+ break
21
+ k = k + 1
22
+ if isValid :
23
+ break
24
+ j = j + 1
25
+ if isValid :
26
+ i = i + 1
27
+ print (numbers [i ], i , len (numbers ))
28
+ part1Num = int (numbers [i ])
29
+ part1Index = i
30
+
31
+ #part 2
32
+ indexMin = - 1
33
+ indexMax = - 1
34
+ for startIndex in range (part1Index ):
35
+ sum = 0
36
+ for i in range (part1Index - startIndex ):
37
+ if sum < part1Num :
38
+ sum = sum + int (numbers [startIndex + i ])
39
+ else :
40
+ break
41
+ i = i + 1
42
+ if sum == part1Num :
43
+ indexMin = startIndex
44
+ indexMax = startIndex + i
45
+ break
46
+ startIndex = startIndex + 1
47
+
48
+ newRange = numbers [indexMin :indexMax ]
49
+ newRange .sort ()
50
+ print (newRange [0 ] + newRange [- 1 ])
You can’t perform that action at this time.
0 commit comments