Teaser 2959: The Magnificent Seven
From The Sunday Times, 9th June 2019 [link] [link]
After a day’s filming, a group of those involved in the film’s production went for a gallop.
They split into threes, with a samurai leading each grouping.
The seven samurai were:
BRONSON, BRYNNER, BUCHHOLZ, COBURN, DEXTER, MCQUEEN and VAUGHN.
The others involved in the gallop were:
ALANIZ, ALONZO, AVERY, BISSELL, BRAVO, DE HOYOS, HERN, LUCERO, NAVARRO, RUSKIN, RUSSELL, SUAREZ, VACIO and WALLACH.
For each grouping, any two names from the three had exactly 2 letters in common (e.g., BRYNNER and BRAVO have B and R in common).
If I told you who accompanied BRONSON, you should be able to tell me who accompanied (a) MCQUEEN and (b) DEXTER.
[teaser2959]







Jim Randell 11:16 pm on 7 June 2019 Permalink |
This Python program runs in 116ms.
Run: [ @repl.it ]
from enigma import (grouping, subsets, diff, unpack, filter_unique, printf) # the "others" others = ( 'ALANIZ', 'ALONZO', 'AVERY', 'BISSELL', 'BRAVO', 'DE HOYOS', 'HERN', 'LUCERO', 'NAVARRO', 'RUSKIN', 'RUSSELL', 'SUAREZ', 'VACIO', 'WALLACH' ) # selection function fn = grouping.share_letters(2) # find a gang for leader x, with remaining members chosen from ys def gang(x, ys): for (y, z) in subsets((y for y in ys if fn(x, y)), size=2): if fn(y, z): yield (y, z) # find multiple gangs, with leaders from x, followers from ys def gangs(xs, ys, gs=[]): # are we done? if not xs: yield gs else: # find a gang for the first leader for g in gang(xs[0], ys): # and solve for the rest yield from gangs(xs[1:], diff(ys, g), gs + [g]) # record possible values for (g1, g2, g3) vs = list() # find possible 2-gangs led by BRONSON, DEXTER, MCQUEEN for gs in gangs(["BRONSON", "DEXTER", "MCQUEEN"], others): # check the remaining 2-gangs can be made with the remaining followers for _ in gangs(["BRYNNER", "BUCHHOLZ", "COBURN", "VAUGHN"], diff(others, *gs)): vs.append(gs) # we only need one example break # "if I told you who accompanied BRONSON ..." f = unpack(lambda B, D, M: B) # "... you could tell me who accompanied MCQUEEN and DEXTER" g = unpack(lambda B, D, M: (M, D)) (ss, _) = filter_unique(vs, f, g) # output solutions for (B, D, M) in ss: printf("BRONSON + {B} -> DEXTER + {D}, MCQUEEN + {M}")Solution: (a) MCQUEEN was accompanied by HERN and RUSSELL. (b) DEXTER was accompanied by AVERY and DE HOYOS.
There are only three possible ways that complete groupings can be made:
Telling us the parters of BRONSON uniquely identifies the solution, so it must the last of these groupings.
LikeLike