-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday3.py
46 lines (36 loc) · 1.05 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
def run(input_path,start=(0,0),slope=(3,1)):
"""
:param input_path:
:return:
"""
lines = open(input_path).readlines()
lines = [line.strip("\n") for line in lines]
rows = len(lines)
cols = len(lines[0])
mx , my = slope
poss_moves = int(rows / my)
currx , curry = start
num_trees = 0
for _ in range(poss_moves):
char = lines[curry][currx % cols]
if char == "#":
num_trees += 1
currx += mx
curry += my
print(f"Number of trees hit {num_trees}")
return num_trees
if __name__ == "__main__":
input_path = "data/day3.txt"
run_part_1 = 1
if run_part_1:
print("running part 1")
run(input_path)
run_part_2 = 1
if run_part_2:
print("running part 2")
run1 = run(input_path,slope=(1,1))
run2 = run(input_path,slope=(3,1))
run3 = run(input_path,slope=(5,1))
run4 = run(input_path,slope=(7,1))
run5 = run(input_path,slope=(1,2))
print(f"Product of trees = {run1*run2*run3*run4*run5}")