diff options
-rw-r--r-- | day6.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/day6.py b/day6.py new file mode 100644 index 0000000..c964cd9 --- /dev/null +++ b/day6.py @@ -0,0 +1,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))) |