Returns the least number for which the proportion of bouncy numbers is exactly 'percent' >>> solution(50) 538 >>> solution(90) 21780 >>> solution(80) 4770 >>> solution(105) Traceback (most recent call last): ... ValueError: solution()
(percent: float = 99)
| 53 | |
| 54 | |
| 55 | def solution(percent: float = 99) -> int: |
| 56 | """ |
| 57 | Returns the least number for which the proportion of bouncy numbers is |
| 58 | exactly 'percent' |
| 59 | >>> solution(50) |
| 60 | 538 |
| 61 | >>> solution(90) |
| 62 | 21780 |
| 63 | >>> solution(80) |
| 64 | 4770 |
| 65 | >>> solution(105) |
| 66 | Traceback (most recent call last): |
| 67 | ... |
| 68 | ValueError: solution() only accepts values from 0 to 100 |
| 69 | >>> solution(100.011) |
| 70 | Traceback (most recent call last): |
| 71 | ... |
| 72 | ValueError: solution() only accepts values from 0 to 100 |
| 73 | """ |
| 74 | if not 0 < percent < 100: |
| 75 | raise ValueError("solution() only accepts values from 0 to 100") |
| 76 | bouncy_num = 0 |
| 77 | num = 1 |
| 78 | |
| 79 | while True: |
| 80 | if check_bouncy(num): |
| 81 | bouncy_num += 1 |
| 82 | if (bouncy_num / num) * 100 >= percent: |
| 83 | return num |
| 84 | num += 1 |
| 85 | |
| 86 | |
| 87 | if __name__ == "__main__": |