euler/python/e191.py

39 lines
822 B
Python

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)