-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path9a.py
More file actions
36 lines (32 loc) · 920 Bytes
/
9a.py
File metadata and controls
36 lines (32 loc) · 920 Bytes
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
#Advent of code
# 07/7/21 day9 9a
#import re
filename = "data9.txt"
preamble_len = 25 #TODO: Set preamble length!
file = open(filename)
filestr = file.read()
a_list = filestr.split("\n")
maxindex = len(a_list)
#print(a_list)
print(f"maxindex={maxindex}, maxcolumns={len(a_list[0])}")
cnt = 0
for entry in a_list:
cnt += 1
print(f"cnt={cnt}")
if cnt <= preamble_len:
continue
start = cnt - preamble_len
found = False
for y in range(start, start+preamble_len ):
for z in range( y+1, cnt ):
print(f"cnt={cnt}, y={y}, z={z}")
sum = int(a_list[y-1]) + int(a_list[z-1])
if int(a_list[cnt-1]) == sum:
print(f"cnt={cnt}, good sum found={sum}")
found = True
break
if found:
break
if not found:
print(f"No sum found! cnt={cnt}, val={a_list[cnt-1]}")
break