adventofcode-2020/03/part2

35 lines
771 B
Python
Executable File

#!/usr/bin/python3
slope = []
with open("input") as fh:
for ln in fh:
row = []
for c in ln:
if c == "#":
row.append(True)
elif c == ".":
row.append(False)
elif c == "\n":
pass
else:
raise RuntimeError("impossible")
slope.append(row)
def trees(slope, right, down):
xmod = len(slope[0])
x = 0
y = 0
trees = 0
while y < len(slope):
trees += slope[y][x % xmod]
x += right
y += down
print(right, down, trees)
return trees
t1 = (trees(slope, 1, 1))
t2 = (trees(slope, 3, 1))
t3 = (trees(slope, 5, 1))
t4 = (trees(slope, 7, 1))
t5 = (trees(slope, 1, 2))
print(t1 * t2 * t3 * t4 * t5)