Returns for given minimum block length the least value of n for which the fill-count function first exceeds one million >>> solution(3) 30 >>> solution(10) 57
(min_block_length: int = 50)
| 28 | |
| 29 | |
| 30 | def solution(min_block_length: int = 50) -> int: |
| 31 | """ |
| 32 | Returns for given minimum block length the least value of n |
| 33 | for which the fill-count function first exceeds one million |
| 34 | |
| 35 | >>> solution(3) |
| 36 | 30 |
| 37 | |
| 38 | >>> solution(10) |
| 39 | 57 |
| 40 | """ |
| 41 | |
| 42 | fill_count_functions = [1] * min_block_length |
| 43 | |
| 44 | for n in count(min_block_length): |
| 45 | fill_count_functions.append(1) |
| 46 | |
| 47 | for block_length in range(min_block_length, n + 1): |
| 48 | for block_start in range(n - block_length): |
| 49 | fill_count_functions[n] += fill_count_functions[ |
| 50 | n - block_start - block_length - 1 |
| 51 | ] |
| 52 | |
| 53 | fill_count_functions[n] += 1 |
| 54 | |
| 55 | if fill_count_functions[n] > 1_000_000: |
| 56 | break |
| 57 | |
| 58 | return n |
| 59 | |
| 60 | |
| 61 | if __name__ == "__main__": |