Sunday Times Teaser 2981 – Faulty Pedometer
by Howard Williams
Published November 10 2019 (link)
Judith is a keen walker who uses a five-digit pedometer to record her number of steps. Her pedometer is inaccurate as some of the counters consistently move on to 0 early by missing out one or more digits. For instance, one of them might roll over from 7 to 0 every time instead of from 7 to 8, missing out digits 8 and 9. She is, however, well aware of this and can work out the correct number of steps.
After walking her usual distance, the pedometer shows 37225 steps but she knows that the true number is 32% less than this. A second distance she walks requires a 30% reduction in the number displayed to give the true number of steps.
How many steps is the second distance?
-
Brian Gladman permalink12345678910111213141516171819202122232425262728293031323334353637from itertools import productfrom functools import reduce# return the pedometer reading for <steps> steps# when the pedometers digits (right to left) have# the first missing digits listed in <bases># (this is a multiple base number representation)def pedometer(steps, bases):bdgts = []for b in bases:steps, d = divmod(steps, b)bdgts.append(d)return reduce(lambda x, y: 10 * x + y, bdgts[::-1])# find a list of first missing digits for the units, tens,# hundreds and thousands pedometer digits that give a# specified reading for a specified number of stepsdef find_fmds(actual, reading):for b4 in product(range(10, 1, -1), repeat=4):# look for the actual and reading values neededif pedometer(actual, b4 + (10,)) == reading:yield b4 + (10,)# find the list of first missing digits that give# a pedometer reading of 37225 for an actual# number of steps that are 32% lowerfor b5 in find_fmds(68 * 37225 // 100, 37225):# now look for an actual number of steps that is 30%# lower than the pedometer reading on this pedometerfor s in range(1, 100000):p = pedometer(s, b5)if p > 100000:breakif 100 * s == 70 * p:print(f"{s:,} steps, pedometer {p:,}, 1st missing digits (ms to ls) {b5[::-1]}")
-
Erling Torkildsen permalink1234567891011121314151617181920212223# It can be shown that if the real number of steps is s, then a pedometer# with bases 10, a, b, c, d for digit places left to right will display:## p(s) = s + (10 - d) * (s // D) + 10 * (10 - c) * (s // C)# + 100 * (10 - b) * (s // B) + 1000 * (10 - a) * (s // A)## where A, B, C and D are the 'place-values' created by the bases.for a in range(6, 11):for b in range(6, 11):for c in range(6, 11):for d in range(6, 11):A, B, C, D, s = d * c * b * a, d * c * b, b * c, d, 25313p = (s + (10 - d) * (s // D) + 10 * (10 - c) * (s // C)+ 100 * (10 - b) * (s // B) + 1000 * (10 - a) * (s//A))if p == 37225:for s in range(10000, 100000):p = (s + (10 - d) * (s // D) + 10 * (10 - c) * (s // C)+ 100 * (10 - b) * (s // B) + 1000 * (10 - a) * (s//A))if 10 * s == 7 * p:print(f"The second distance is {int(s)} steps.")