Solve 114 through 117.

This commit is contained in:
2023-10-03 20:53:27 +02:00
parent 41f8cc1345
commit 67526f1978
4 changed files with 140 additions and 0 deletions

31
python/e116.py Normal file
View File

@@ -0,0 +1,31 @@
from functools import lru_cache
@lru_cache()
def block_combinations(row_length: int, block_length: int = 3):
if row_length < 0:
return 0
if row_length == 0:
return 1
result = block_combinations(row_length - 1, block_length)
result += block_combinations(row_length - block_length, block_length)
return result
def solve(row_length: int):
r = block_combinations(row_length, 2) - 1
r += block_combinations(row_length, 3) - 1
r += block_combinations(row_length, 4) - 1
return r
def euler_116():
return solve(50)
if __name__ == "__main__":
solution = euler_116()
print("e116.py: " + str(solution))
assert(solution == 20492570929)