New Scientist Enigma 871 – Pandigitals
by Colin Singleton
From Issue #2026, 20th April 1996 [link]
Uncle Joe had written the digits 0 to 9 on ten cards, some red, the others blue, one digit per card. “Now boys,” he said, “you have to arrange the red cards on the table to form a number, and divide the blue cards into two groups to form two separate numbers. The ‘red’ number must be the product of the ‘blue’ numbers.”
“Like this?” said Tom. “Or this?” said Dick. “Or this?” said Harry.
“All different, and all correct!” replied Uncle Joe.
Only Tom had included a single-digit number in his arrangement. What was Harry’s ‘red’ number?
One Comment
Leave one →
-
Brian Gladman permalink12345678910111213141516171819202122232425262728293031323334353637from itertools import combinations, permutationsfrom collections import defaultdict# The possible numeric arrangements are:## Tom: a x bcde = fghij# Dick and Harry: ab x cde = fghijred2ns = defaultdict(list)# consider all combinations of five red digitsfor r in combinations('0123456789', 5):red = ''.join(r)# consider all arrangements of the blue digitsblue = set('0123456789').difference(red)for b in permutations(blue):# consider Tom's arrangement (sp = 1 -> a x bcde)# and Dick/Harry's arrangement (sp = 2 -> ab x cde)for sp in (1, 2):x, y = ''.join(b[:sp]), ''.join(b[sp:])if '0' not in {x[0], y[0]}:i, j = int(x), int(y)spr = ''.join(sorted(str(i * j)))if spr == red and ('0' in blue or '0' in spr):red2ns[red].append((i, j))for red, nbrs in red2ns.items():# we need one 'Tom' and two 'Dick/Harry' arrangementsfor a, b, c in combinations(sorted(nbrs), 3):if a[0] < 10 and b[0] >= 10 and c[0] >= 10:print( " BLUE RED")print(f"Tom: {a[0]} x {a[1]} = {a[0] * a[1]}")print(f"Dick/Harry: {b[0]} x {b[1]} = {b[0] * b[1]}")print(f"Dick/Harry: {c[0]} x {c[1]} = {c[0] * c[1]}")