-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay3.py
46 lines (35 loc) · 1 KB
/
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
45
46
# Starting at the top-left corner of your map and following a slope of right 3 and down 1, how many trees would you encounter?
import math
forest = []
while True:
line = input()
if line == "end":
break
forest.append(line)
# repeat pattern to the right
num_columns = 7 * len(forest)
while len(forest[0]) < num_columns:
for i in range(len(forest)):
forest[i] += forest[i]
def part_one():
pos = 0
num_trees = 0
for i in range(len(forest)):
if forest[i][pos] == "#":
num_trees += 1
pos += 3
print(num_trees)
def part_two():
slopes = [[1, 1], [3, 1], [5, 1], [7, 1], [1, 2]]
num_trees = []
for i in range(len(slopes)):
pos = 0
num_trees_slope = 0
for j in range(0, len(forest), slopes[i][1]):
if forest[j][pos] == "#":
num_trees_slope += 1
pos += slopes[i][0]
num_trees.append(num_trees_slope)
print(num_trees)
print(math.prod(num_trees))
part_two()