blob: c964cd9918952b3e146515e3b36cba560a6377ab (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
#!/usr/bin/env python
with open("day6.txt") as data:
population = [num for num in map(int, next(data).strip().split(','))]
memo = {}
def count_children(age, time):
if (age, time) not in memo:
result = 0
if time == 0:
result = 1
elif age == 0:
result = count_children(6, time - 1) + count_children(8, time - 1)
else:
result = count_children(age - 1, time - 1)
memo[(age, time)] = result
return memo[(age, time)]
# part 1
print(sum(map(lambda x: count_children(x, 80), population)))
# part 2
print(sum(map(lambda x: count_children(x, 256), population)))
|