aoc2020/3.py

36 lines
777 B
Python
Raw Normal View History

2020-12-04 12:27:13 +00:00
def run_by(right, down):
trees = 0
print((right, down))
with open("3.txt") as f:
idx = 0
for i, line in enumerate(f):
line = line.strip()
l = list(line)
c = line[idx % len(line)]
if i % down == 0:
l[idx % len(l)] = "X" if c == "#" else "O"
print(f"{idx}\t{len(line)}\t{''.join(l)}\t{line}")
if i % down == 0:
idx += right
if i == 0: continue
if i % down == 0:
if c == "#":
trees += 1
print()
return trees
s = [
run_by(1, 1),
run_by(3, 1),
run_by(5, 1),
run_by(7, 1),
run_by(1, 2),
]
print(s)
import math
print(math.prod(s))