Re: list combinations
- To: mathgroup@smc.vnet.net
- Subject: [mg11022] Re: [mg11000] list combinations
- From: Daniel Lichtblau <danl@wolfram.com>
- Date: Mon, 16 Feb 1998 18:15:26 -0500
- References: <199802160840.DAA11510@smc.vnet.net.>
Daniel Sanders wrote:
>
> Hi All,
>
> I have a bit of bother here about creating a list. The problem: Given a
> set of lists of the same dimension, example
> list={{1,2},{2,3},{5,6},{7,8}}, I want to join them in sets of two such
> that every combination is joined. So, if list is of Dimensions={5,2},
> the new list will be of Dimensions={10,2,2}. I think that states the
> basic problem. I want to use standard issue Mathematica functions
> without calling up a package, or simulating the style of another
> program language like Pascal.
>
> Thanks in advance for any help.
>
> Dan
In[18]:= list = {{1,2},{2,3},{5,6},{7,8}};
In[19]:= Dimensions[list]
Out[19]= {4, 2}
In[20]:= combos = Flatten[Table[{list[[j]],list[[k]]},
{j,Length[list]-1}, {k,j+1,Length[list]}], 1]
Out[20]= {{{1, 2}, {2, 3}}, {{1, 2}, {5, 6}}, {{1, 2}, {7, 8}},
> {{2, 3}, {5, 6}}, {{2, 3}, {7, 8}}, {{5, 6}, {7, 8}}}
In[21]:= Dimensions[combos]
Out[21]= {6, 2, 2}
Daniel Lichtblau
Wolfram Research
- References:
- list combinations
- From: Daniel Sanders <dman777@earthlink.net>
- list combinations