Returns the number of different ways can the grey tiles in a row of the given length be replaced if colours cannot be mixed and at least one coloured tile must be used >>> solution(5) 12
(length: int = 50)
| 36 | |
| 37 | |
| 38 | def solution(length: int = 50) -> int: |
| 39 | """ |
| 40 | Returns the number of different ways can the grey tiles in a row |
| 41 | of the given length be replaced if colours cannot be mixed |
| 42 | and at least one coloured tile must be used |
| 43 | |
| 44 | >>> solution(5) |
| 45 | 12 |
| 46 | """ |
| 47 | |
| 48 | different_colour_ways_number = [[0] * 3 for _ in range(length + 1)] |
| 49 | |
| 50 | for row_length in range(length + 1): |
| 51 | for tile_length in range(2, 5): |
| 52 | for tile_start in range(row_length - tile_length + 1): |
| 53 | different_colour_ways_number[row_length][tile_length - 2] += ( |
| 54 | different_colour_ways_number[row_length - tile_start - tile_length][ |
| 55 | tile_length - 2 |
| 56 | ] |
| 57 | + 1 |
| 58 | ) |
| 59 | |
| 60 | return sum(different_colour_ways_number[length]) |
| 61 | |
| 62 | |
| 63 | if __name__ == "__main__": |