Solve 114 through 117.
This commit is contained in:
30
python/e117.py
Normal file
30
python/e117.py
Normal file
@@ -0,0 +1,30 @@
|
||||
from functools import lru_cache
|
||||
|
||||
|
||||
@lru_cache()
|
||||
def block_combinations(row_length: int):
|
||||
block_sizes = [2, 3, 4]
|
||||
if row_length < 0:
|
||||
return 0
|
||||
|
||||
if row_length == 0:
|
||||
return 1
|
||||
|
||||
# space
|
||||
result = block_combinations(row_length - 1)
|
||||
|
||||
# one of the blocks
|
||||
for block_length in block_sizes:
|
||||
result += block_combinations(row_length - block_length)
|
||||
|
||||
return result
|
||||
|
||||
|
||||
def euler_117():
|
||||
return block_combinations(50)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
solution = euler_117()
|
||||
print("e117.py: " + str(solution))
|
||||
assert(solution == 100808458960497)
|
||||
Reference in New Issue
Block a user