Sunday Times Teaser 2857 – Significant Errors
by Danny Roth
Published June 25 2017 (link)
Last year George and Martha were going to visit one of their daughters. Her house number was a two-figure number but unfortunately Martha wrote the number incorrectly by making the first digit less than it should be. When George discovered the error he commented that the incorrect number was a whole number percentage of the correct one. If you knew that percentage then you should be able to work out their daughter’s house number.
Then the daughter moved to a different two-figure house number, Martha again wrote the number incorrectly by making the first digit less than it should be, and again the incorrect number was a whole number percentage of the correct one. If you knew that percentage then you should be able to work out their daughter’s new house number.
What was the daughter’s original house number, and what is the new one?
-
Brian Gladman permalink12345678910111213141516171819202122232425262728293031323334from collections import defaultdict# consider incorrect numbers as percentages of correct ones,# mapping percentages to lists of number pairs giving themp2np = defaultdict(list)# consider the daughter's possible house numbersfor nbr in range(20, 100):# ... and the tens digit of the incorrect onefor i in range(1, nbr // 10):inbr = 10 * i + nbr % 10# look for integer percentagesp, r = divmod(100 * inbr, nbr)if not r:p2np[p].append((nbr, inbr))# look for percentages leading to unique house numbersfor p, l_fnbr in p2np.items():if len(l_fnbr) == 1:# the first correct and incorrect house numbersfnbr, ifnbr = l_fnbr[0]# recreate the map from percentages to lists of number# pairs excluding the daughter's first house numberq2np = {p:[t for t in l_np if t[0] != fnbr] for p, l_np in p2np.items()}# ... and again look for percentages leading to unique house numbersfor q, l_snbr in q2np.items():if len(l_snbr) == 1:# the second correct and incorrect house numberssnbr, isnbr = l_snbr[0]print(f'first: {fnbr} ({ifnbr}), second: {snbr} ({isnbr})')