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: [mg121671] Re: 1-liner wanted
  • From: Ulrich Arndt <ulrich.arndt at data2knowledge.de>
  • Date: Sat, 24 Sep 2011 22:35:42 -0400 (EDT)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • References: <201109230743.DAA07699@smc.vnet.net>

Depends on what you want this might work

1. only one result set is of interest

pat = {{_Integer, _Integer, _Integer} ...,
   x : {a_Integer, b_Integer,
     x1_Integer}, {_Integer, _Integer, _Integer} ...,
   y : {b_Integer, c_Integer,
     x2_Integer}, {_Integer, _Integer, _Integer} ...,
   z : {a_Integer, c_Integer,
     x3_Integer}, {_Integer, _Integer, _Integer} ...};

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

givenList /. pat -> {x, y, z}

2. all which match the pattern are of interest
patshort = {{a_Integer, b_Integer, _Integer}, {b_Integer,
   c_Integer, _Integer}, {a_Integer, c_Integer, _Integer}};

Extract[KSubsets[givenList, 3],
 Position[Map[MatchQ[#, patshort] &, KSubsets[givenList, 3]], True]]

Ulrich

--
www.data2knowledge.de


Am 23.09.2011 um 09:43 schrieb Kent Holing:

> 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: difference between two commands
  • Next by Date: Re: 1-liner wanted
  • Previous by thread: 1-liner wanted
  • Next by thread: Re: 1-liner wanted