Sunday Times Teaser 2534 – Fiftieth Anniversary
by Victor Bryant
Published: 17 April 2011 (link)
We have recently celebrated the 50th anniversary of the Teaser column. At the party for the setters they gave each letter of the alphabet a different number from 1 to 26 (eg they made A=7). Appropriately, this was done in such a way that, for each setter present, the values of the letters of their surname added up to 50. Angela Newing was there (so N+E+W+I+N+G=50), as were Nick MacKinnon and Hugh Bradley. Only two of Graham Smithers, Danny Roth, Andrew Skidmore, John Owen and Victor Bryant could make it.
Which two?
One Comment
Leave one →
-
Brian Gladman permalink12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273# This teaser will be too slow without some prior analysis.## We have:## B + R + A + D + L + E + Y = 50# M + A + C + K + I + N + N + O + N = 50## Adding these gives:## A + 2.N + sum(A, B, C, D, E, I, K, L, M, N, O, R, Y) = 100## The minimum value of 13 different numbers is 91 so A + 2.N is# at most 9. And we are told that A = 7 so N must be 1 and all# the letters in the sum are in the range 1..13 inclusive.from itertools import permutationsfrom functools import reducefrom sys import exit# possible attendees at the anniversaryguests = ('Victor Bryant', 'John Owen', 'Andrew Skidmore','Graham Smithers', 'Danny Roth')# values from the preliminary analysisl2d ={ 'A':7, 'N':1 }# permute the digits needed for MacKinnon and check its digit sumfor p1 in permutations(set(range(2, 14)).difference([7]), 5):l2d.update(zip('CIKMO', p1))if sum(l2d[c] for c in 'MACKINNON') != 50:continue# permute the new digits needed for Bradley and check its digit sumfor p2 in permutations(set(range(2, 14)).difference(p1 + (7,))):l2d.update(zip('BRDLEY', p2))if sum(l2d[c] for c in 'BRADLEY') != 50:continue# now find the digit values needed to make the digit sum# for Newing equal to 50for g in range(14, 27):w = 50 - g - sum(l2d[c] for c in 'NEIN')if not 14 <= w <= 27:continuel2d.update(zip('GW', (g, w)))# at this point we can sum the letter values for some# possible guests and hence tell if they are present;# for those with surnames with unallocated letters we# we don't necessarily need to know their letter sums# since unallocated letters are at least 14 and this# may already mean that their sums must be above 50possible = list(guests)for g in guests:surname = g.split()[1].upper()# find the sum of already assigned lettersval = 50 - sum(l2d[c] for c in surname if c in l2d)# find the unassigned lettersltrs = ''.join(c for c in surname if c not in l2d)# remove guests if their digit sums cannot be fiftyif not ltrs and val != 50 or 14 * len(ltrs) > val:possible.remove(g)# if only two guests are possible they must provide# the solutionif len(possible) == 2:print('{} and {}.'.format(*possible))exit(0)