Re: Combinations
- To: mathgroup at smc.vnet.net
- Subject: [mg49721] Re: Combinations
- From: sean_incali at yahoo.com (sean kim)
- Date: Thu, 29 Jul 2004 07:44:37 -0400 (EDT)
- References: <ce5dk5$b87$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
In[39]:=
Outer[List,{a,b,c},{a,b,c}, {a,b,c}]
%//Flatten[#,2]&
%//Length
Out[39]=
{{{{a,a,a},{a,a,b},{a,a,c}},{{a,b,a},{a,b,b},{a,b,c}},{{a,c,a},{a,c,b},{a,c,
c}}},{{{b,a,a},{b,a,b},{b,a,c}},{{b,b,a},{b,b,b},{b,b,c}},{{b,c,a},{b,
c,b},{b,c,c}}},{{{c,a,a},{c,a,b},{c,a,c}},{{c,b,a},{c,b,b},{c,b,
c}},{{c,c,a},{c,c,b},{c,c,c}}}}
Out[40]=
{{a,a,a},{a,a,b},{a,a,c},{a,b,a},{a,b,b},{a,b,c},{a,c,a},{a,c,b},{a,c,c},{b,a,
a},{b,a,b},{b,a,c},{b,b,a},{b,b,b},{b,b,c},{b,c,a},{b,c,b},{b,c,c},{c,a,
a},{c,a,b},{c,a,c},{c,b,a},{c,b,b},{c,b,c},{c,c,a},{c,c,b},{c,c,c}}
Out[41]=
27
does what you want i think.
hth
sean
Gregory Lypny <gregory.lypny at videotron.ca> wrote in message news:<ce5dk5$b87$1 at smc.vnet.net>...
> Hello everyone,
>
> Does Mathematica have a built-in function that will generate a simple
> list all possible combinations of a list of strings? For example,
> {a,b,c}, where the elements are strings, should give 3x3=27 triplets of
> "aaa", "aba", etc.
>
> I tried
>
> In[4]:=Outer[{a,b,c},{a,b,c},{a,b,c}]
>
> but I get
>
> {{{a, b, c}[a, a], {a, b, c}[a, b], {
> a, b, c}[a, c]}, {{a, b, c}[b, a], {a, b, c}[b, b], {a, b,
> c}[b, c]}, {{a, b, c}[c, a], {a, b, c}[c, b], {a, b, c}[c, c]}}
>
> which is going to be difficult to match with my data using BinCounts
> and the like.
>
> Regards,
>
> Greg