Sunday Times Teaser 2771 – All Saints Day
by Andrew Skidmore
Published: 1 November 2015 (link)
I have written down three even numbers and then consistently replaced digits by letters with different letters used for different digits. In this way I get
ALL   THE   SAINTS
In fact multiplying together the first two of these numbers gives the third.
What number is my SAINT?
2 Comments
Leave one →
-
Brian Gladman permalink123456789101112131415161718192021222324252627from itertools import permutations# permute the digits for L, E and S (all even)for L, E, S in permutations('02468', 3):# permute digits for the remaining letters in ALL and THEs = set('0123456789').difference([L, E, S])for A, H, T in permutations(s, 3):# leading digits must be non-zeroif '0' not in (A, T, S):# now form the numbers represented by ALL and THEALL = int(A + L + L)THE = int(T + H + E)# now compute SAINTS, checking that it is the right length# and that any duplicates of digits already set are corrects, a, I, N, t, *r = SAINTS = str(ALL * THE)if r and a == a and t == T and S == s == r[0]:# check that I and N are different and not one# of the digits that have already been usedif I != N and not set((A, E, H, L, S, T)) & set((I, N)):print('SAINT = ' + SAINTS[:-1])
-
geoffrounce permalink1234567891011121314151617181920212223242526272829from itertools import permutationsdigits = set('1234567890')# construct ALLfor (a, l) in permutations(digits, 2):if a == '0': continueall = int(a + l + l)if all % 2 != 0 : continue#construct THEfor (t, h, e) in permutations(digits.difference(set((a, l))), 3):if t == '0' : continuethe = int(t + h + e)if the % 2 != 0 : continue#construct SAINTSfor (s, i, n) in permutations(digits.difference(set((a, l, t, h, e))), 3):if s == '0' : continuesaints = int(s + a + i + n + t + s)if saints % 2 != 0: continue#construct SAINTif all * the == saints:saint = int(s + a + i + n + t)print('ALL={}, THE={}, SAINTS={}, SAINT={}'.format(all, the, saints, saint))