Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2011

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: 1-liner wanted

  • To: mathgroup at smc.vnet.net
  • Subject: [mg121651] Re: 1-liner wanted
  • From: Bob Hanlon <hanlonr at cox.net>
  • Date: Sat, 24 Sep 2011 22:32:02 -0400 (EDT)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • Reply-to: hanlonr at cox.net

givenlist = {{1, 2, 3}, {2, 4, 5}, {6, 7, 8}, {1, 4, 6}, {7, 8, 
    9}, {11, 12, 13}};

givenlist /. {___, x : {a_, b_, _}, ___, y : {b_, c_, _}, ___, 
   z : {a_, c_, _}, ___} ->
  {x, y, z}

{{1, 2, 3}, {2, 4, 5}, {1, 4, 6}}

givenlist /. {___, {a_, b_, d_}, ___, {b_, c_, e_}, ___, {a_, c_, 
    f_}, ___} ->
  {{a, b, d}, {b, c, e}, {a, c, f}}

{{1, 2, 3}, {2, 4, 5}, {1, 4, 6}}


Bob Hanlon

---- Kent Holing <KHO 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





  • Prev by Date: Re: 1-liner wanted
  • Next by Date: Re: help with integration
  • Previous by thread: Re: 1-liner wanted
  • Next by thread: Re: 1-liner wanted