Find m for which the proportion of perfect partitions to total partitions is lower than max_proportion >>> solution(1) > 5 True >>> solution(1/2) > 10 True >>> solution(3 / 13) > 185 True
(max_proportion: float = 1 / 12345)
| 61 | |
| 62 | |
| 63 | def solution(max_proportion: float = 1 / 12345) -> int: |
| 64 | """ |
| 65 | Find m for which the proportion of perfect partitions to total partitions is lower |
| 66 | than max_proportion |
| 67 | |
| 68 | >>> solution(1) > 5 |
| 69 | True |
| 70 | |
| 71 | >>> solution(1/2) > 10 |
| 72 | True |
| 73 | |
| 74 | >>> solution(3 / 13) > 185 |
| 75 | True |
| 76 | |
| 77 | """ |
| 78 | |
| 79 | total_partitions = 0 |
| 80 | perfect_partitions = 0 |
| 81 | |
| 82 | integer = 3 |
| 83 | while True: |
| 84 | partition_candidate = (integer**2 - 1) / 4 |
| 85 | # if candidate is an integer, then there is a partition for k |
| 86 | if partition_candidate == int(partition_candidate): |
| 87 | partition_candidate = int(partition_candidate) |
| 88 | total_partitions += 1 |
| 89 | if check_partition_perfect(partition_candidate): |
| 90 | perfect_partitions += 1 |
| 91 | if ( |
| 92 | perfect_partitions > 0 |
| 93 | and perfect_partitions / total_partitions < max_proportion |
| 94 | ): |
| 95 | return int(partition_candidate) |
| 96 | integer += 1 |
| 97 | |
| 98 | |
| 99 | if __name__ == "__main__": |
no test coverage detected