29 lines
705 B
Python
29 lines
705 B
Python
|
from functools import lru_cache
|
||
|
|
||
|
|
||
|
@lru_cache()
|
||
|
def block_combinations(row_length: int, min_block_length: int = 3):
|
||
|
if row_length == 0:
|
||
|
return 1
|
||
|
result = 0
|
||
|
result = block_combinations(row_length - 1, min_block_length)
|
||
|
for new_block in range(min_block_length, row_length):
|
||
|
result += block_combinations(row_length - new_block - 1, min_block_length)
|
||
|
if row_length >= min_block_length:
|
||
|
result += 1
|
||
|
return result
|
||
|
|
||
|
|
||
|
def euler_115():
|
||
|
for n in range(1000):
|
||
|
if block_combinations(n, 50) > 10**6:
|
||
|
return n
|
||
|
return -1
|
||
|
|
||
|
|
||
|
if __name__ == "__main__":
|
||
|
solution = euler_115()
|
||
|
print("e115.py: " + str(solution))
|
||
|
assert(solution == 168)
|
||
|
|