-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay01.py
More file actions
32 lines (23 loc) · 815 Bytes
/
Day01.py
File metadata and controls
32 lines (23 loc) · 815 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
26
27
28
29
30
31
32
from Utility import *
filePath = 'input/day01/part1.txt'
def solvePart1():
inputLines = getLinesFromFile(filePath)
values = list(map(int, inputLines))
numberOfIncreases = 0
for i, line in enumerate(values[1:]):
if (line > values[i]):
numberOfIncreases += 1
print('Solution to part1:')
print(numberOfIncreases)
def solvePart2():
inputLines = getLinesFromFile(filePath)
values = list(map(int, inputLines))
def calculateSlidingWindow(index):
return sum(values[index:index+3])
numberOfIncreases = sum(map(lambda i: 1 if calculateSlidingWindow(
i) > calculateSlidingWindow(i-1) else 0, range(1, len(values)-2)))
print('Solution to part2:')
print(numberOfIncreases)
if(__name__ == '__main__'):
solvePart1()
solvePart2()