Set by Tom Smith and Michael Cronnelly
- JavaScript
Some positive integers n have the property that the sum of (n + reverse(n)) consists entirely of odd digits.
For instance:
When n = 36 then 36 + 63 = 99
When n = 409 then 409 + 904 = 1313
We will call such numbers reversible; so 36, 63, 409, and 904 are reversible.
If the reverse of n has a leading zero then n is not considered reversible.
For instance:
10 + 01 is ignored and 10 is not
There are 120 reversible numbers below 1000.
Develop a solution that can take any integer as an upper limit and returns all the reversible numbers from 1 to the upper limit, as an array.
Your class/module should have the following interface:
- listReversible(upperLimit) - Return an array of all the reversibles between 1 and upperLimit
- reverseNumber(number) - Returns the reverse of number. When number = 36 will return 63 and when number = 10 will return 1
- isOdd(number) - Returns true if number is odd