-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay06.py
More file actions
50 lines (32 loc) · 1.23 KB
/
Day06.py
File metadata and controls
50 lines (32 loc) · 1.23 KB
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
import Utility
filePath = 'input/day06/part1.txt'
def getInitialPopulationSpread(inputLines: list[str]) -> list[int]:
members = list(map(int, inputLines[0].split(',')))
populationSpread = []
for i in range(9):
populationSpread.append(len(list(filter(lambda m: m == i, members))))
return populationSpread
def stepPopulation(populationSpread: list[int]) -> list[int]:
newSpread = [0 for i in range(9)]
for i in range(8):
newSpread[i] += populationSpread[i + 1]
newSpread[8] += populationSpread[0]
newSpread[6] += populationSpread[0]
return newSpread
def simulatePopulation(populationSpread, steps):
for i in range(steps):
populationSpread = stepPopulation(populationSpread)
return populationSpread
def solvePart1():
inputLines = Utility.getLinesFromFile(filePath)
population = getInitialPopulationSpread(inputLines)
print('Solution to part1:')
print(sum(simulatePopulation(population, 80)))
def solvePart2():
inputLines = Utility.getLinesFromFile(filePath)
population = getInitialPopulationSpread(inputLines)
print('Solution to part2:')
print(sum(simulatePopulation(population, 256)))
if(__name__ == '__main__'):
solvePart1()
solvePart2()