mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-11-23 21:11:08 +00:00
Add Project Euler problem 117 solution 1 (#6872)
Update DIRECTORY.md --------- Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
This commit is contained in:
parent
ee778128bd
commit
9720e6a6cf
|
@ -956,6 +956,8 @@
|
|||
* [Sol1](project_euler/problem_115/sol1.py)
|
||||
* Problem 116
|
||||
* [Sol1](project_euler/problem_116/sol1.py)
|
||||
* Problem 117
|
||||
* [Sol1](project_euler/problem_117/sol1.py)
|
||||
* Problem 119
|
||||
* [Sol1](project_euler/problem_119/sol1.py)
|
||||
* Problem 120
|
||||
|
|
0
project_euler/problem_117/__init__.py
Normal file
0
project_euler/problem_117/__init__.py
Normal file
53
project_euler/problem_117/sol1.py
Normal file
53
project_euler/problem_117/sol1.py
Normal file
|
@ -0,0 +1,53 @@
|
|||
"""
|
||||
Project Euler Problem 117: https://projecteuler.net/problem=117
|
||||
|
||||
Using a combination of grey square tiles and oblong tiles chosen from:
|
||||
red tiles (measuring two units), green tiles (measuring three units),
|
||||
and blue tiles (measuring four units),
|
||||
it is possible to tile a row measuring five units in length
|
||||
in exactly fifteen different ways.
|
||||
|
||||
|grey|grey|grey|grey|grey| |red,red|grey|grey|grey|
|
||||
|
||||
|grey|red,red|grey|grey| |grey|grey|red,red|grey|
|
||||
|
||||
|grey|grey|grey|red,red| |red,red|red,red|grey|
|
||||
|
||||
|red,red|grey|red,red| |grey|red,red|red,red|
|
||||
|
||||
|green,green,green|grey|grey| |grey|green,green,green|grey|
|
||||
|
||||
|grey|grey|green,green,green| |red,red|green,green,green|
|
||||
|
||||
|green,green,green|red,red| |blue,blue,blue,blue|grey|
|
||||
|
||||
|grey|blue,blue,blue,blue|
|
||||
|
||||
How many ways can a row measuring fifty units in length be tiled?
|
||||
|
||||
NOTE: This is related to Problem 116 (https://projecteuler.net/problem=116).
|
||||
"""
|
||||
|
||||
|
||||
def solution(length: int = 50) -> int:
|
||||
"""
|
||||
Returns the number of ways can a row of the given length be tiled
|
||||
|
||||
>>> solution(5)
|
||||
15
|
||||
"""
|
||||
|
||||
ways_number = [1] * (length + 1)
|
||||
|
||||
for row_length in range(length + 1):
|
||||
for tile_length in range(2, 5):
|
||||
for tile_start in range(row_length - tile_length + 1):
|
||||
ways_number[row_length] += ways_number[
|
||||
row_length - tile_start - tile_length
|
||||
]
|
||||
|
||||
return ways_number[length]
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
print(f"{solution() = }")
|
Loading…
Reference in New Issue
Block a user