<jupyter_start><jupyter_text>Problem 112 Bouncy numbersWorking 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\%$.Find the least number for which the proportion of bouncy numbers is exactly $99\%$. Solution<jupyter_code>from euler.numbers import get_digits
def compute(n: float) -> int:
    bouncy = 0
    i = 1
    while bouncy / i < n:
        i += 1
        digits = list(get_digits(i))
        sorted_digits = sorted(digits)
        if not (digits == sorted_digits or digits == sorted_digits[::-1]):
            bouncy += 1
    return i

compute(0.5)
compute(0.9)
compute(0.99)
%timeit -n 100 -r 1 -p 6 compute(0.99)<jupyter_output>2.21533 s ± 0 ns per loop (mean ± std. dev. of 1 run, 100 loops each)
{'fraction_non_alphanumeric': 0.08303249097472924, 'fraction_numerical': 0.04909747292418772, 'mean_word_length': 3.6824324324324325, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '548292', 'license': 'MIT', 'n_tokens_mistral': 472, 'n_tokens_neox': 413, 'n_words': 197, 'path': 'problems/0112/solution.ipynb', 'repo_name': 'Dynortice/didactic-rotary-phone', 'size': '1385'}