-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathday3.py
44 lines (34 loc) · 826 Bytes
/
day3.py
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import math
def get_tree_count(geology, x_move, y_move):
count = 0
y_coord, x_coord = 0, 0
y_length, x_length = len(geology), len(geology[0])
while (y_coord + 1) <= y_length:
if geology[y_coord][x_coord % x_length] == '#':
count += 1
x_coord += x_move
y_coord += y_move
return count
def part1(geology):
return get_tree_count(geology, 3, 1)
def part2(geology):
slopes = [
(1, 1),
(3, 1),
(5, 1),
(7, 1),
(1, 2),
]
return math.prod(
[
get_tree_count(geology, slope[0], slope[1])
for slope in slopes
]
)
with open('day3-data.txt') as f:
inputs = [
line
for line in f.read().splitlines()
]
print(part1(inputs))
print(part2(inputs))