5 kyu

Ratio of Bouncy Numbers

77 of 310cave.on

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.
Mathematics
Puzzles

Stats:

CreatedOct 24, 2015
PublishedOct 24, 2015
Warriors Trained1130
Total Skips131
Total Code Submissions1039
Total Times Completed310
JavaScript Completions77
Ruby Completions31
Python Completions162
Haskell Completions10
Rust Completions21
Go Completions19
C# Completions21
Total Stars23
% of votes with a positive feedback rating92% of 79
Total "Very Satisfied" Votes68
Total "Somewhat Satisfied" Votes9
Total "Not Satisfied" Votes2
Total Rank Assessments12
Average Assessed Rank
5 kyu
Highest Assessed Rank
3 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • cave.on Avatar
  • GiacomoSorbi Avatar
  • raulbc777 Avatar
  • JohanWiltink Avatar
  • hobovsky Avatar
  • user8436785 Avatar
  • akar-0 Avatar
  • dfhwze Avatar
  • saudiGuy Avatar
Ad