Problem Statement
Analysis
This problem asks for the least positive integer
such that the proportion of "bouncy" numbers up to
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
, and
be the count of non-bouncy numbers
.
The condition is
.
Since
, the condition becomes:
This means we seek the smallest
such that
.
A key consequence is that
must be a multiple of 100.
Non-bouncy numbers are either increasing or decreasing.
Let
be the count of increasing numbers
and
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
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
(
), indicating
is likely greater than
.
The computational strategy is:
1. Implement functions (likely using Digit DP) to compute
accurately for any
.
2. Search for the target
by checking multiples of 100, starting from an estimated lower bound (e.g.,
).
3. The first
found such that
is the solution.
Solution
Link to solution: https://git.charlesreid1.com/cs/euler/src/branch/master/java/Problem112.java
Flag