109 - Bouncy Numbers

109 - Bouncy Numbers#

This is problem 112 from Project Euler.

An “increasing number” is when, working from left-to-right, no digit is exceeded by the digit to its left. For example, 134468.

Similarly, a “decreasing number” is when no digit is exceeded by the digit to its right. 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 (1) just over half of the numbers below one-thousand (525) are bouncy. In fact, (2) the least number for which the proportion of bouncy numbers first reaches 50% is 538.

Surprisingly, bouncy numbers become more and more common and (3) by the time we reach 21780 the proportion of bouncy numbers is equal to 90%.

Tasks:

  • Confirm the three statements above:

  • Find the least number for which the proportion of bouncy numbers is exactly 99%.