-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday3.py
More file actions
25 lines (20 loc) · 702 Bytes
/
day3.py
File metadata and controls
25 lines (20 loc) · 702 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
from functools import reduce
def ready_data(down=1):
with open('inputs/day3.txt') as f:
data = f.readlines()[::down]
data = [list(x.strip('\n')) for x in data]
return data
def encountered_trees(right, down=1):
trees = 0
for i, line in enumerate(ready_data(down)):
if line[i * right % len(line)] == '#':
trees += 1
return trees
def multiple_trees(lst_of_slopes):
result = [encountered_trees(*x) for x in lst_of_slopes]
return reduce((lambda x,y: x*y), result)
if __name__ == '__main__':
print("First part:")
print(encountered_trees(3,1))
print("Second part")
print(multiple_trees([(1,1), (3,1), (5,1), (7,1), (1,2)]))