Teaser 2600: Mileometer
From The Sunday Times, 22nd July 2012 [link] [link]
My car’s digital mileometer has five digits, displaying whole miles. It also has a trip meter with five digits, displaying tenths of a mile (which resets to zero when reaching 10,000 miles). Soon after the car was new I reset the trip meter to zero (but never did that again). Not long after, I noticed that the two five-digit displays were the same ignoring the decimal point). The next time the displays were the same I wrote down the mileage and did so on each subsequent occasion until the mileage reached 100,000. The sum of all the mileages I wrote down was 500,000.
What were the five digits when the displays were first the same?
[teaser2600]


Jim Randell 9:57 am on 3 December 2024 Permalink |
Suppose the readings are the same at a distance ABCDE+F miles (the +F indicates + F tenths of a mile), then the readings are:
The trip meter is actually reading XABCD+E miles, since it was reset, for some non-visible digit X.
Which means the trip meter was reset at an actual distance of:
And we want this to be soon after the car was new, maybe in the first 10K miles.
This Python program looks at distances of possible duplicated readings, and collects them by the trip reset distance. It then looks for a distance where the sum of the milometer readings (except for the first one) is 500000.
It runs in 530ms (using PyPy).
from enigma import (defaultdict, irange, subsets, nconcat, trim, printf) # collect readings by reset distance rs = defaultdict(list) # consider possible 6-digit distances (in 0.1 mile units) for (A, B, C, D, E, F) in subsets(irange(0, 9), size=6, select='M'): dist = nconcat(A, B, C, D, E, F) for X in irange(max(0, A - 1), A): # consider trip distances that match the milometer (in 0.1 mile units) trip = nconcat(X, A, B, C, D, E) # calculate trip reset point k = dist - trip if not (0 < k < 100000): continue rs[k].append(dist) # output the milometer/trip readings def output(d, k): (m, f) = divmod(d, 10) (t, g) = divmod(d - k, 10) t %= 10000 printf("@ {m:05d}.{f} miles -> {m:05d} + {t:04d}.{g}") # consider possible reset distances for (k, vs) in rs.items(): vs = sorted(vs) # sum the milometer readings (except the first one) t = sum(v // 10 for v in trim(vs, head=1)) if t == 500000: # output solution output(k, k) for v in vs: output(v, k) printf("t = {t}") printf()Solution: When the displays were first the same they were showing 01235 (or 0123.5 for the trip meter).
The trip meter was reset as a distance of 1111.6 miles, and so the readings were:
And the sum of the values noted down is:
LikeLike