Sunday Times Teaser 2800 – Promoting Rugby
by Graham Smithers
Published: 22 May 2016 (link)
Six male rugby players and six female rugby players are helping to promote the game. The men are Eastmond, Morgan, Twelvetrees, Webber, Yarde and Youngs. The women are Allen, Clarke, Croker, McGilchrist, McLean and Thompson. The men have paired off with the women and one pair has gone to each of the counties East Sussex, Hampshire, Isle of Wight, Norfolk, Suffolk and Surrey. For each pair, if you look at the name of the man, the name of the woman and the name of their county, then for any two of the three names just two different letters of the alphabet occur in both (possibly more than once).
The men above are listed in alphabetical order: in that order, who are their female partners?
-
Brian Gladman permalink123456789101112131415161718192021222324252627282930313233343536373839from itertools import permutationsmen = ('Eastmond', 'Morgan', 'Twelvetrees', 'Webber', 'Yarde', 'Youngs')women = ('Allen', 'Clarke', 'Croker', 'McGilchrist', 'McLean', 'Thompson')places = ('East Sussex', 'Hampshire', 'Isle of Wight', 'Norfolk','Suffolk', 'Surrey')# map the names to their sets of lettersm2sl = {w:set(w.lower()) for w in men}w2sl = {w:set(w.lower()) for w in women}p2sl = {w:set(w.lower()) for w in places}# permute the womenfor pw in permutations(women):# ensure that all men's and women's names share two lettersif all(len(m2sl[m] & w2sl[w]) == 2 for m, w in zip(men, pw)):# permute the place namesfor pp in permutations(places):# ensure that all men's and place names share two lettersif all(len(m2sl[m] & p2sl[p]) == 2 for m, p in zip(men, pp)):# ensure that all women's and place names share two lettersif all(len(w2sl[w] & p2sl[p]) == 2 for w, p in zip(pw, pp)):# output the answers = ', '.join(pw)f, s, l = s.rpartition(', ')print('{}.'.format(f + ' and ' + l))# output the three associationss = [', '.join(x) for x in zip(men, pw, pp)]print('({}).'.format(')\n('.join(s)))