# Enigmatic Code

Programming Enigma Puzzles

## Enigma 1150: Cubic meter

From New Scientist #2306, 1st September 2001 [link]

My car has a five-figure display for the milometer, showing the total miles travelled since the car was made, and a three-figure display for an odometer (which can be set to zero at the beginning of a trip) to measure the distance of a journey. When I got the car both meters were showing perfect cubes with no zeros. I also noticed that both notched up the next mile simultaneously.

I never reset the odometer, it just keeps going round and round, going back to zero when it reaches one thousand. Once when it was at zero the milometer was again showing a perfect cube. (In fact it was the second occasion since I bought the car that the odometer had been at zero, but you don’t need to know that). I have run the car for several years since then (although the milometer has never gone back to zero yet).

As I parked this morning I noticed that again both meters were displaying perfect cubes with no zeros.

What were the two meters displaying this morning?

[enigma1150]

### One response to “Enigma 1150: Cubic meter”

1. Jim Randell 12 September 2016 at 7:41 am

This Python program runs in 37ms

```from enigma import irange, is_cube, printf

# consider the initial reading on the milometer
# (a 5-digit cube with no zeros)
for j in irange(22, 46):
milo1 = j ** 3
if '0' in str(milo1): continue

# and the initial reading on the odometer
# (a 3-digit cube with no zeros)
for k in irange(5, 9):
odo1 = k ** 3
if '0' in str(odo1): continue

# the milometer reading the next but one time the odometer
# reaches 0 should also be a cube
milo2 = milo1 + 2000 - odo1
j2 = is_cube(milo2)
if j2 is None: continue

# look for final reading for the milometer
# (a 5-digit cube with no zeros)
for j3 in irange(j2 + 1, 46):
milo3 = j3 ** 3
if '0' in str(milo3): continue

# and the odometer reading would be...
odo3 = (odo1 + milo3 - milo1) % 1000
# it must be a 3-digit cube with no zeros
if '0' in str(odo3): continue
k3 = is_cube(odo3)
if k3 is None: continue

printf("milo1={milo1} ({j}^3) odo1={odo1} ({k}^3), milo2={milo2} ({j2}^3), milo3={milo3} ({j3}^3) odo3={odo3} ({k3}^3)")
```

Solution: The reading on the milometer is 97336 (= 46³). The reading on the odometer is 512 (= 8³).

The initial readings are: 12167 (= 23³) and 343 (= 7³).

And the second time the odometer reaches 0 the milometer reading is 13824 (= 24³).