Sunday Times Teaser 2705 – In the Pub
by Danny Roth
The words DRANK, GLASS and LAGER represent three numbers in which different digits, all non-zero, have been consistently replaced by different letters. These numbers are in increasing order and the third is equal to the sum of the first two.
What number is represented by ALE?
One Comment
Leave one →
-
brian gladman permalink12345678910111213141516171819202122232425from itertools import permutations# permute letters for GLASS and LAGERfor p in permutations(range(1, 10), 6):a, e, g, l, r, s = p# compute the three valuesglass = 10000 * g + 1000 * l + 100 * a + 10 * s + slager = 10000 * l + 1000 * a + 100 * g + 10 * e + rdrank = lager - glass# check that we have three five digit values in increasing orderif 10000 < drank < glass < lager:# check that the R and A in DRANK match the values we already haveif (drank // 100) % 100 == 10 * r + a:# extract the digits from DRANK for the letters D, N and Kdnk = set((drank // 10000, (drank // 10) % 10, drank % 10))# and check that there are three of them with no zero digits# and no values that we already haveif len(dnk) == 3 and not (0 in dnk or dnk.intersection(p)):fs = 'ALE = {} (DRANK = {}, GLASS = {}, LAGER = {}).'print(fs.format(100 * a + 10 * l + e, drank, glass, lager))