-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path3b.py
More file actions
51 lines (46 loc) · 1.37 KB
/
3b.py
File metadata and controls
51 lines (46 loc) · 1.37 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#Advent of code
# 12/7/2020 day3 3b
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])}")
maxcol = len(a[0]) # 11 in short data, longer in real file
maxline = maxindex - 1 #10 in short data file, longer in real file
def findtrees(maxcol, maxline, col_inc, line_inc):
line = 0
col = 0
trees = 0
while True:
col = col + col_inc
if col >= maxcol:
col = col - maxcol
line = line + line_inc
if line > maxline:
#print(f"total trees = {trees}")
print(f"col_inc = {col_inc}, line_inc = {line_inc}, foundtrees = {trees}")
return 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}")
mul = 1
#col_inc = 3
#line_inc = 1
foundtrees = findtrees(maxcol, maxline, 1, 1)
mul = mul * foundtrees
foundtrees = findtrees(maxcol, maxline, 3, 1)
mul = mul * foundtrees
foundtrees = findtrees(maxcol, maxline, 5, 1)
mul = mul * foundtrees
foundtrees = findtrees(maxcol, maxline, 7, 1)
mul = mul * foundtrees
foundtrees = findtrees(maxcol, maxline, 1, 2)
mul = mul * foundtrees
print(f"final mul = {mul}")