Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #5192

Re: 1-liner wanted

From Ulrich Arndt <ulrich.arndt@data2knowledge.de>
Newsgroups comp.soft-sys.math.mathematica
Subject Re: 1-liner wanted
Date 2011-09-25 02:45 +0000
Organization Steven M. Christensen and Associates, Inc and MathTensor, Inc.
Message-ID <j5m4l6$pot$1@smc.vnet.net> (permalink)
References <201109230743.DAA07699@smc.vnet.net> <DFE49833-2F0A-4B8E-8D35-B266BCA2E83D@data2knowledge.de>

Show all headers | View raw


Sorry - second one needs to be

Extract[Subsets[givenList, {3}],
  Position[Map[MatchQ[#, patshort] &, Subsets[givenList, {3}]],
   True]] // Timing

to avoid Combinatorica`

package...

Ulrich

Am 23.09.2011 um 11:03 schrieb Ulrich Arndt:

> 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
>>
>

Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread


Thread

Re: 1-liner wanted Ulrich Arndt <ulrich.arndt@data2knowledge.de> - 2011-09-25 02:45 +0000

csiph-web