Re: 1-liner wanted
- To: mathgroup at smc.vnet.net
- Subject: [mg121672] Re: 1-liner wanted
- From: Ulrich Arndt <ulrich.arndt at data2knowledge.de>
- Date: Sat, 24 Sep 2011 22:35:53 -0400 (EDT)
- Delivered-to: l-mathgroup@mail-archive0.wolfram.com
- References: <201109230743.DAA07699@smc.vnet.net> <DFE49833-2F0A-4B8E-8D35-B266BCA2E83D@data2knowledge.de>
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 >> >
- References:
- 1-liner wanted
- From: Kent Holing <KHO@statoil.com>
- 1-liner wanted