27 lines
626 B
Python
Executable File
27 lines
626 B
Python
Executable File
#!/usr/bin/env python3
|
|
|
|
import sys
|
|
import numpy as np
|
|
from functools import reduce
|
|
|
|
def hit(l, i):
|
|
return l[i] == '#'
|
|
|
|
def trees(lines, x, bank, spd):
|
|
if not lines:
|
|
return 0
|
|
return hit(lines[0], x) + trees(lines[spd:],
|
|
(x + bank) % len(lines[0]),
|
|
bank, spd)
|
|
|
|
fn = sys.argv[1] if len(sys.argv) > 1 else 'input3'
|
|
with open(fn) as f:
|
|
|
|
lines = [l.strip() for l in f.readlines()]
|
|
|
|
ct = trees(lines, 0, 3, 1)
|
|
print(ct)
|
|
|
|
ct = np.prod([trees(lines, 0, nx, ny) for nx, ny in ((1,1), (3,1), (5,1), (7,1), (1,2))])
|
|
print(ct)
|