Solve problem 191.
This commit is contained in:
38
python/e191.py
Normal file
38
python/e191.py
Normal 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)
|
||||||
|
|
||||||
Reference in New Issue
Block a user