Re: 1-liner wanted

*To*: mathgroup at smc.vnet.net*Subject*: [mg121666] Re: 1-liner wanted*From*: Ray Koopman <koopman at sfu.ca>*Date*: Sat, 24 Sep 2011 22:34:46 -0400 (EDT)*Delivered-to*: l-mathgroup@mail-archive0.wolfram.com*References*: <j5hdfe$7j5$1@smc.vnet.net>

On Sep 23, 12:45 am, Kent Holing <K... at statoil.com> wrote: > Let's assume we have a list of elements of the type {x,y,z} > for x, y and z integers. And, if needed we assume x < y < z. > We also assume that the list contains at least 3 such triples. > > Can Mathematica easily solve the following problem? To detect at > least three elements from the list of the type {a,b,.}, {b,c,.} > and {a,c,.}? I am more intereseted in an elegant 1-liner than > computational efficient solutions. > > Example: > Givenlist = {1,2,3},{2,4,5],{6,7,8},{1,4,6},{7,8,9},{11,12,13}}; > should return > {{1,2,3},{2,4,5},{1,4,6}} > > Kent Holing, > Norway This gives what you want for this particular Givenlist: Cases[Subsets[Givenlist,{3}],{{a_,b_,_},{b_,c_,_},{a_,c_,_}}] {{{1,2,3},{2,4,5},{1,4,6}}} However, you might need to consider permutations: Cases[Flatten[Permutations/@Subsets[Givenlist,{3}], 1], {{a_,b_,_},{b_,c_,_},{a_,c_,_}}] {{{1,2,3},{2,4,5},{1,4,6}}} r = Reverse@Givenlist {{11,12,13},{7,8,9},{1,4,6},{6,7,8},{2,4,5},{1,2,3}} Cases[Subsets[r,{3}],{{a_,b_,_},{b_,c_,_},{a_,c_,_}}] {} Cases[Flatten[Permutations/@Subsets[r,{3}],1], {{a_,b_,_},{b_,c_,_},{a_,c_,_}}] {{{1,2,3},{2,4,5},{1,4,6}}}