Solve 114 through 117.
This commit is contained in:
31
python/e116.py
Normal file
31
python/e116.py
Normal 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)
|
||||
Reference in New Issue
Block a user