Sunday Times Teaser 2496 – No Title
by DJT Hogg
Published July 25 2010 (link)
I have chosen 10 different letters of the alphabet before U to represent the digits 0 to 9. I can tell you that 0’s letter is in the word NOUGHT, 1’s letter is in the word ONE, 2’s letter is in TWO, and so on up to 9’s letter, being in the word NINE.
Furthermore, I can write down a particular five-figure number that is divisible by 8, and replacing the digits by their letters I get EIGHT. Similarly, a four-figure number divisible by 9 translates to NINE.
What number is represented by TEN?
One Comment
Leave one →
-
Brian Gladman permalink1234567891011121314151617181920212223242526272829303132333435363738394041from functools import reducenbrs = ('NOUGHT', 'ONE', 'TWO', 'THREE', 'FOUR', 'FIVE', 'SIX', 'SEVEN','EIGHT', 'NINE')# (digit, letters) pairs giving the possible letters for each digitd2ls = tuple((i, set(x).difference('UVWXYZ')) for i, x in enumerate(nbrs))# map letters to digits consistent with the (digit letter) pairs in d2lsdef map_d2l(d2ls, l2d=dict()):# is the map complete?if len(l2d.keys()) == 10:yield l2delse:# find the next digit with a minimum number of possible lettersdl_min = min(d2ls, key=lambda x: len(x[1]))dgt = dl_min[0]# try each possible letterfor ltr in dl_min[1]:# create and update the mapping frrom letters to digitsn_l2d = l2d.copy()n_l2d[ltr] = dgt# remove the allocated letter from the possibilities for the# remaining digitsn_d2ls = tuple((i, x - {ltr}) for i, x in d2ls if i != dgt)# check that all remaining digits still have possible lettersif all(x for i, x in n_d2ls):# and proceed to the next digit if they doyield from map_d2l(n_d2ls, n_l2d)# convert a string of letters to a number according to the map in l2ds2n = lambda s: reduce(lambda x, y: 10 * x + y, (l2d[c] for c in s))for l2d in map_d2l(d2ls):# find the numeric values for EIGHT, NINE and TENeight, nine, ten = s2n('EIGHT'), s2n('NINE'), s2n('TEN')# check that EIGHT and NINE are divisible by 8 and 9 respectivelyif eight % 8 == 0 and nine % 9 == 0:print(f'TEN = {ten} (EIGHT = {eight}, NINE = {nine}).')