Ratio of Bouncy Numbers
Description:
Working from left-to-right if no digit is exceeded by the digit to its left it is called an increasing number; for example, 134468
.
Similarly if no digit is exceeded by the digit to its right it is called a decreasing number; for example, 66420
.
We shall call a positive integer that is neither increasing nor decreasing a "bouncy" number; for example, 155349
.
Clearly there cannot be any bouncy numbers below one-hundred, but just over half of the numbers below one-thousand (525
) are bouncy. In fact, the least number for which the proportion of bouncy numbers first reaches 50% is 538
.
Surprisingly, bouncy numbers become more and more common and by the time we reach 21780
the proportion of bouncy numbers is equal to 90%.
Your Task
Complete the bouncyRatio
function.
The input will be the target ratio.
The output should be the smallest number such that the proportion of bouncy numbers reaches the target ratio.
You should throw an Error
for a ratio less than 0% or greater than 99%.
Source
Updates
- 26/10/2015: Added a higher precision test case.
Similar Kata:
Stats:
Created | Oct 24, 2015 |
Published | Oct 24, 2015 |
Warriors Trained | 1130 |
Total Skips | 131 |
Total Code Submissions | 1039 |
Total Times Completed | 310 |
JavaScript Completions | 77 |
Ruby Completions | 31 |
Python Completions | 162 |
Haskell Completions | 10 |
Rust Completions | 21 |
Go Completions | 19 |
C# Completions | 21 |
Total Stars | 23 |
% of votes with a positive feedback rating | 92% of 79 |
Total "Very Satisfied" Votes | 68 |
Total "Somewhat Satisfied" Votes | 9 |
Total "Not Satisfied" Votes | 2 |
Total Rank Assessments | 12 |
Average Assessed Rank | 5 kyu |
Highest Assessed Rank | 3 kyu |
Lowest Assessed Rank | 7 kyu |