# Enigmatic Code

Programming Enigma Puzzles

## Enigma 551: Mileage mix up

From New Scientist #1704, 17th February 1990 [link]

When I sold my old car last week I noticed something odd about the total mileage (a five figure number) displayed on its milometer: if the digits in this number were summed they formed a perfect square. Also, the results of multiplying this square by the original number was to give a figure which was an exact multiple of the number formed by reversing the digits in the mileage. Furthermore, if the square was multiplied by this reverse number, it gave a figure which was an exact multiple of the mileage.

However, the really strange thing was that when I bought my new car, which had a lower mileage than my old car, exactly the same properties applied to its total mileage. Neither of the totals were divisible by 10 or palindromic (that is, the number formed by reversing the digits was different to the original mileage but also had five figures)

What were the total mileages of: (a) my old car; (b) my new car?

[enigma551]

### One response to “Enigma 551: Mileage mix up”

1. Jim Randell 1 June 2020 at 8:13 am

The following Python program looks at all possible 5-digit numbers. It runs in 150ms.

Run: [ @repl.it ]

```from enigma import subsets, irange, is_square, nconcat, div, printf

# choose 5 digits, n = ABCDE, r = EDCBA
for (A, B, C, D, E) in subsets(irange(0, 9), size=5, select="M"):
# neither n nor r are divisible by 10
if A == 0 or E == 0: continue
# neither n (nor r) is palindromic
if A == E and B == D: continue

# the sum of the digits is a perfect square
s = A + B + C + D + E
if is_square(s) is None: continue

# n * s is a multiple of r
n = nconcat(A, B, C, D, E)
r = nconcat(E, D, C, B, A)
if div(n * s, r) is None: continue

# r * s is a multiple of n
if div(r * s, n) is None: continue

printf("{A}{B}{C}{D}{E}, sum = {s}")
```

Solution: (a) The mileage on the old car was 89991. (b) The mileage on the new car was 19998.

We have:

19998, digit sum = 36 = 6².
89991, digit sum = 36 = 6².

19998 × 36 = 89991 × 8
89991 × 36 = 19998 × 162

This site uses Akismet to reduce spam. Learn how your comment data is processed.