-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path3a.py
More file actions
34 lines (30 loc) · 758 Bytes
/
3a.py
File metadata and controls
34 lines (30 loc) · 758 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
#Advent of code
# 12/7/2020 day3 3a
filename = "data3.txt"
file = open(filename)
filestr = file.read()
a_str = filestr.split("\n")
a = a_str
maxindex = len(a)
print(a)
print(f"maxindex={maxindex}, maxcolumns={len(a[0])}")
line = 0
col = 0
maxcol = len(a[0]) # 11 in short data, longer in real file
maxline = maxindex - 1 #10 in short data file, longer in real file
trees = 0
while True:
col = col + 3
if col >= maxcol:
col = col - maxcol
line = line + 1
if line > maxline:
print(f"total trees = {trees}")
break
current = a[line]
print (f"col={col}, line={line}, linelen={len(current)}")
val = current[col]
if val == "#":
trees = trees + 1
print (f"val={val}, trees = {trees}")
exit()