Project Euler 112 - Bouncy Numbers

Official link: https://projecteuler.net/problem=112

Thought Process

I have 2 functions:

  1. is_bouncy(number)

    • Function takes a number list and produces a temp variable = list(str(number)), I figured it would be fast to directly check if this list is = to the same list sorted or to the same list sorted then reversed, if it is it means it is increasing or decreasing respectively

    • If it is the function returns False, else it returns True

  2. compute(percentage)

    • Initialise 2 variables bouncy_numbers = 0 and total = 1

    • Start a while loop that ends when bouncy_numbers/total does not equal percentage

    • Keep increasing total and if is_bouncy(total) = True increase the bouncy_numbers count

Interactive Code

Enter an integer (yourinput)

Code will output the least number for which the proportion of bouncy numbers is exactly yourinput%