Returns the number of ways a row of the given length can be filled >>> solution(7) 17
(length: int = 50)
| 33 | |
| 34 | |
| 35 | def solution(length: int = 50) -> int: |
| 36 | """ |
| 37 | Returns the number of ways a row of the given length can be filled |
| 38 | |
| 39 | >>> solution(7) |
| 40 | 17 |
| 41 | """ |
| 42 | |
| 43 | ways_number = [1] * (length + 1) |
| 44 | |
| 45 | for row_length in range(3, length + 1): |
| 46 | for block_length in range(3, row_length + 1): |
| 47 | for block_start in range(row_length - block_length): |
| 48 | ways_number[row_length] += ways_number[ |
| 49 | row_length - block_start - block_length - 1 |
| 50 | ] |
| 51 | |
| 52 | ways_number[row_length] += 1 |
| 53 | |
| 54 | return ways_number[length] |
| 55 | |
| 56 | |
| 57 | if __name__ == "__main__": |