From 2a181cdbd173c3a10375befb04f09c3e73638c9a Mon Sep 17 00:00:00 2001 From: felixm Date: Sun, 14 Apr 2024 08:05:46 -0400 Subject: [PATCH] Solve problem 191. --- python/e191.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 python/e191.py diff --git a/python/e191.py b/python/e191.py new file mode 100644 index 0000000..3e84153 --- /dev/null +++ b/python/e191.py @@ -0,0 +1,38 @@ +from functools import lru_cache + + +@lru_cache +def count(days_left, absent_count): + if absent_count > 1: + return 0 + if days_left == 0: + return 1 + if days_left < 0: + return 0 + c = 0 + c += count(days_left - 1, absent_count + 1) # "a" + c += count(days_left - 2, absent_count + 1) # "la" + c += count(days_left - 3, absent_count + 1) # "lla" + + c += count(days_left - 1, absent_count) # "o" + c += count(days_left - 2, absent_count) # "lo" + c += count(days_left - 3, absent_count) # "llo" + + if days_left == 2: + c += 1 # "ll" + + if days_left == 1: + c += 1 # "l" + + return c + + +def euler_191(): + return count(30, 0) + + +if __name__ == "__main__": + solution = euler_191() + print("e191.py: " + str(solution)) + assert(solution == 1918080160) +