Project Euler 145: Count reversible numbers in a range
Problem Description
Some positive integers n have the property that the sum [ n + reverse(n) ] consists entirely of odd (decimal) digits. For instance, 36 + 63 = 99 and 409 + 904 = 1313. We will call such numbers reversible; so 36, 63, 409, and 904 are reversible. Leading zeroes are not allowed in either n or reverse(n).
There are 120 reversible numbers below one-thousand.
How many reversible numbers are there below one-billion (109)?
Analysis
Staring at the patterns from a brute force run revealed two simple formulas that calculate the number of reversible numbers below 10n. There are:
- No solutions for n = {1, 5, 9, 13, …},
- For even n there are 20 * 30n/2 − 1 solutions, and
- For odd n, not already excluded, there are 100 * 500(n/4) solutions.
Project Euler 145 Solution
Runs < 0.001 seconds in Python 2.7.
Use this link to get the Project Euler 145 Solution Python 2.7 source.Afterthoughts
-
No afterthoughts yet.
Project Euler 145 Solution last updated
Discussion
No comments yet.