aoc/03/03_refactored.py

12 lines
358 B
Python
Raw Normal View History

2020-12-04 04:29:19 +00:00
with open("input.txt","r") as f:
tmap = f.read().split('\n')
def trees(right, down, tmap=tmap):
count = 0
for row, line in enumerate(tmap[::down]): # array slicing by step
if line[ row * right % len(tmap[0]) ] == "#":
count += 1
return count
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)}')