Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2004
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2004

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

Search the Archive

Re: All combinations

  • To: mathgroup at smc.vnet.net
  • Subject: [mg47373] Re: [mg47357] All combinations
  • From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
  • Date: Wed, 7 Apr 2004 03:16:31 -0400 (EDT)
  • References: <200404061036.GAA09271@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

On 6 Apr 2004, at 19:36, János wrote:


> Hi,
>
> I need in a list of all 'k' length combinations of set of 'n' different
> elements where k can be smaller or bigger than n.  For example if I
> have n=4 and the set is {a,b,c,d} then all combinations of k=7 length
> would be
>
> {{a,a,a,a,a,a,a}
> {a,a,a,a,a,a,b}
> {a,a,a,a,a,b,a}
> ...
> ...
> {d,d,d,d,d,d,d}}
>
> and the Length of it is about 4^7, in general n^k.
>
> I looked <<DiscreteMath`Combinatorica and  found Permutations, but it
> is just a subset I am looking for.  I can program it out, but would
> prefer a built in or add-on functions if one is already there.
>
> Can you point me to the right direction ?
>
> Thanks ahead,
> János
> -----------------------------------------------------
> So, while openness provides a couple of security advantages in itself,
> the chief reason why Linux and BSD offer superior security is not so
> much because they're open source, but because they're not Windows.
> http://www.theregister.co.uk/content/55/36029.html
>
>


There is no build in function but:


AllCombinations[S_List,k_]:=Distribute[Table[S,{k}],List]

dos the trick, e.g:


Length[AllCombinations[{a,b,c,d},7]]

16384


Andrzej Kozlowski
Chiba, Japan
http://www.mimuw.edu.pl/~akoz/


  • Prev by Date: Comparison of Mathematica on Various Computers
  • Next by Date: Re: Scientific Notation in ListPlot Axes
  • Previous by thread: All combinations
  • Next by thread: Re: All combinations