Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #5182
| From | Peter Pein <petsie@dordos.net> |
|---|---|
| Newsgroups | comp.soft-sys.math.mathematica |
| Subject | Re: 1-liner wanted |
| Date | 2011-09-25 02:40 +0000 |
| Organization | Steven M. Christensen and Associates, Inc and MathTensor, Inc. |
| Message-ID | <j5m4al$pme$1@smc.vnet.net> (permalink) |
| References | <j5hdfe$7j5$1@smc.vnet.net> |
Am 23.09.2011 09:45, 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
>
This looks like some kind of homework, but my proposal is far from being
elegant - so what...
In[1]:= Givenlist = {{1, 2, 3}, {2, 4, 5}, {6, 7, 8}, {6, 8, new},
{1, 4, 6}, {7, 8, 9}, {11, 12, 13}};
In[2]:= With[{pat = Permutations[{{a, b, x}, {b, c, y}, {a, c, z}}]},
Flatten[(ReplaceList[Givenlist,
Insert[Map[Pattern[#1, _] & , #1, {2}], ___, Transpose[{Range[4]}]]
:> pat[[1]]] & ) /@ pat, 1]]
Out[2]= {{{1, 2, 3}, {2, 4, 5}, {1, 4, 6}},
{{6, 7, 8}, {7, 8, 9}, {6, 8, new}}}
or - to keep elements in order - a small change immediately after ":>"
In[3]:= With[{pat = Permutations[{{a, b, x}, {b, c, y}, {a, c, z}}]},
Flatten[(ReplaceList[Givenlist,
Insert[Map[Pattern[#1, _] & , #1, {2}], ___, Transpose[{Range[4]}]]
:> #] & ) /@ pat, 1]]
Out[3]= {{{1, 2, 3}, {2, 4, 5}, {1, 4, 6}},
{{6, 7, 8}, {6, 8, new}, {7,8,9}}}
Peter Pein,
Germany
Back to comp.soft-sys.math.mathematica | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
1-liner wanted Kent Holing <KHO@statoil.com> - 2011-09-23 07:45 +0000 Re: 1-liner wanted "andre.robin3" <andre.robin3@wanadoo.fr> - 2011-09-25 02:37 +0000 Re: 1-liner wanted Peter Pein <petsie@dordos.net> - 2011-09-25 02:40 +0000 Re: 1-liner wanted Ray Koopman <koopman@sfu.ca> - 2011-09-25 02:42 +0000 Re: 1-liner wanted "Oleksandr Rasputinov" <oleksandr_rasputinov@hmamail.com> - 2011-09-25 09:43 +0000
csiph-web