Sunday Times Teaser 3053 – Endless Number
by Danny Roth
Published Sunday March 28 2021 (link)
George and Martha have a telephone number consisting of nine digits; there is no zero and the others appear once each. The total of the digits is obviously 45, so that the number is divisible by nine. Martha noticed that, if she removed the last (ie, the least significant) digit, an eight-digit number would remain, divisible by eight. George added that you could continue this process, removing the least significant digit each time to be left with an n-digit number divisible by n right down to the end.
What is their telephone number?
5 Comments
Leave one →
By trading shortcuts (from analysis) for a uniform routine, a recursive-like approach can be used:
You can also consider only b’s which have the same type (odd/even) as n.
The same puzzle has already been published on this site:
New Scientist Puzzle 102
A straightforward solution:
Another solution that doesn’t use the imported ‘permutations’ function
but uses an ad hoc recursive function:
Yes, this ship sailed many moons ago but I kept tweaking.
This version is more computationally efficient but contains 2 additional lines of code to deal with the fifth digit which analysis shows must = 5 and separates the odd and even digits.
‘whatsleft’ is renamed ‘dr’