From 659d106cc6e92fc8ab89044b3ca260a26a9647ca Mon Sep 17 00:00:00 2001 From: Brian Chu Date: Sun, 5 Dec 2021 22:42:46 -0800 Subject: solution for day 6 --- day6.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 day6.py 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))) -- cgit 1.4.1-2-gfad0