Sunday Times Teaser 2761 – Digital Shuffle
by Danny Roth
Published: 23 August 2015 (link)
George and Martha have nine cards with a different non-zero digit on each. To teach their nephew to count they lined up the cards in increasing order. He then rearranged the order of the line and Martha was impressed when she noticed that no digit was in its original position. George was even more impressed when he found that the six-figure number formed by the last six cards was the square of the three-figure number formed by the first three.
What was that three-figure number?
One Comment
Leave one →
-
Brian Gladman permalink1234567891011121314from itertools import permutations# pick the three digit numberfor p3 in permutations('123456789', 3):n3 = int(''.join(p3))# form the sequence of n followed by n ** 2q = p3 + tuple(str(n3 ** 2))# check it has nine different non-zero digitsif '0' not in q and len(q) == len(set(q)) == 9:# and that it is a derangementif not any(str(i + 1) == v for i, v in enumerate(q)):print('{}^2 = {}'.format(n3, n3 ** 2))