Solve problem 191.

main
felixm 2024-04-14 08:05:46 -04:00
parent 642432cef8
commit 2a181cdbd1
1 changed files with 38 additions and 0 deletions

38
python/e191.py Normal file
View File

@ -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)