2021-01-04 13:59:11 +03:00
|
|
|
from fileio import open
|
|
|
|
let f = open('test/day3.in')
|
|
|
|
let lines = f.read().split('\n')[:-1]
|
|
|
|
|
|
|
|
def count_trees(lines, x_off, y_off):
|
|
|
|
let modulo = len(lines[0])
|
|
|
|
let x = 0, y = 0, trees = 0
|
|
|
|
while y < len(lines):
|
|
|
|
if lines[y][x % modulo] == '#':
|
|
|
|
trees += 1
|
|
|
|
x += x_off
|
|
|
|
y += y_off
|
|
|
|
return trees
|
|
|
|
|
2021-01-04 17:33:43 +03:00
|
|
|
print("part 1:", count_trees(lines, 3, 1))
|
|
|
|
print("part 2:", count_trees(lines, 1, 1) * count_trees(lines, 3, 1) * count_trees(lines, 5, 1) * count_trees(lines, 7, 1) * count_trees(lines, 1, 2))
|