Problem Statement
 
Analysis
This problem asks for the least positive integer  such that the proportion of "bouncy" numbers up to
 such that the proportion of "bouncy" numbers up to  is exactly 99%.
 is exactly 99%. 
A number is bouncy if it is neither increasing (digits non-decreasing left-to-right, e.g., 13448) nor decreasing (digits non-increasing left-to-right, e.g., 99740).
Let  be the count of bouncy numbers
 be the count of bouncy numbers  , and
, and  be the count of non-bouncy numbers
 be the count of non-bouncy numbers  .
.
The condition is  .
.
Since  , the condition becomes:
, the condition becomes:
 
This means we seek the smallest  such that
 such that  .
.
A key consequence is that  must be a multiple of 100.
 must be a multiple of 100.
Non-bouncy numbers are either increasing or decreasing. 
Let  be the count of increasing numbers
 be the count of increasing numbers  and
 and  be the count of decreasing numbers
 be the count of decreasing numbers  .
. 
Numbers with all identical digits (e.g., 555) are both increasing and decreasing; let their count be  .
.
By inclusion-exclusion:
 
While calculating  for arbitrary
 for arbitrary  typically requires Digit Dynamic Programming, analytical formulas exist for
 typically requires Digit Dynamic Programming, analytical formulas exist for  :
:
 
 
 
 
These formulas show that the proportion of non-bouncy numbers drops below 1.3% for  (
 ( ) and below 0.4% for
) and below 0.4% for  (
 ( ), indicating
), indicating  is likely greater than
 is likely greater than  .
.
The computational strategy is:
1. Implement functions (likely using Digit DP) to compute  accurately for any
 accurately for any  .
.
2. Search for the target  by checking multiples of 100, starting from an estimated lower bound (e.g.,
 by checking multiples of 100, starting from an estimated lower bound (e.g.,  ).
).
3. The first  found such that
 found such that  is the solution.
 is the solution.
Solution
Link to solution: https://git.charlesreid1.com/cs/euler/src/branch/master/java/Problem112.java
Flag