-
Notifications
You must be signed in to change notification settings - Fork 0
/
Day 03 1.py
50 lines (35 loc) · 880 Bytes
/
Day 03 1.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
47
48
49
50
from tools import *
import math
lines = readFileToStrings("Input03")
space = "."
tree = "#"
slopes = [[1, 1],
[3, 1],
[5, 1],
[7, 1],
[1, 2]]
arrayOfTreecount = []
def evaluatePosition(char):
if char == space:
return 0
elif char == tree:
return 1
else:
return -10000
def runWithSlope(horizontalStep, verticalStep):
countOfTrees = 0
xPos = 0
yPos = 0
for line in lines:
if (yPos % verticalStep != 0):
yPos += 1
continue
countOfTrees += evaluatePosition(line[xPos])
xPos += horizontalStep
yPos += 1
if xPos >= (len(line) - 1):
xPos = xPos % (len(line) - 1)
return countOfTrees
for slope in slopes:
arrayOfTreecount.append(runWithSlope(slope[0], slope[1]))
print(math.prod(arrayOfTreecount))