aoc/03/03_refactored2.py

6 lines
322 B
Python

with open("input.txt","r") as f:
tmap = f.read().split('\n')
def trees(dx, dy, tmap=tmap):
return sum( [ line[i*dx % len(line)] == "#" for i, line in enumerate(tmap[::dy])] ) # array stepping AND list comprehension
print(f'Part 1: {trees(3,1)}')
print(f'Part 2: {trees(1,1)*trees(3,1)*trees(5,1)*trees(7,1)*trees(1,2)}')