32 lines
702 B
Python
32 lines
702 B
Python
|
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)
|