MathGroup Archive 2004

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Combinations

  • To: mathgroup at smc.vnet.net
  • Subject: [mg49696] Re: [mg49672] Combinations
  • From: Sseziwa Mukasa <mukasa at jeol.com>
  • Date: Thu, 29 Jul 2004 07:43:05 -0400 (EDT)
  • References: <200407271100.HAA11164@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

On Jul 27, 2004, at 7:00 AM, Gregory Lypny wrote:

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

You want to use

Flatten[Outer[List, {a, b, c}, {a, b, c}, {a, b, c}], 2]

The first argument to outer is a function that's applied to the 
combinations.  The rest of the arguments are the lists to combine.  The 
Flatten reduces the rank of the tensor that's returned, see the help 
browser for details.

Regards,

Ssezi


  • References:
    • Combinations
      • From: Gregory Lypny <gregory.lypny@videotron.ca>
  • Prev by Date: Re: Any ways to recover a broken file?
  • Next by Date: Re: Combinations
  • Previous by thread: Combinations
  • Next by thread: Re: Combinations