Terminology
An increasing number is one where each digit is greater than or equal to all the digits to the left of it (ex. 12239)
A decreasing number is one where each digit is less than or equal to all the digits to the left of it (ex. 95531)
A bouncy number is any number that is not increasing or decreasing. Since this requires at least 3 digits, the first bouncy number is 101
The task
Given an integer n greater than or equal to 1, find the sum of the first n bouncy numbers
Rules
- This is code golf, so the answer with the shortest amount of bytes wins
- If your language has limits on integer size (ex. 2^32-1) n will be small enough that the sum will fit in the integer
- Input can be any reasonable form (stdin, file, command line parameter, integer, string, etc)
- Output can be any reasonable form (stdout, file, graphical user element that displays the number, etc)
Test cases
1 > 101
10 > 1065
44701 > 1096472981
sort
the numbers and check if they're the same as the original number? That's using a built-in (sort
), but it's not strictly a built-in to check if it's increasing. Check out Non-observable program requirements and Do X without Y on our "Things to avoid" Meta post. \$\endgroup\$