blob: c964cd9918952b3e146515e3b36cba560a6377ab (
plain) (
tree)
|
|
#!/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)))
|