MathGroup Archive 2004

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

Search the Archive

Re: All combinations

  • To: mathgroup at
  • Subject: [mg47375] Re: All combinations
  • From: astanoff_otez_ceci at (astanoff)
  • Date: Wed, 7 Apr 2004 03:16:33 -0400 (EDT)
  • References: <c4u3ih$9lc$>
  • Sender: owner-wri-mathgroup at

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}}
I couldn't find any builtin solution, but I had fun writing this :
repetitivePermutations[elements_List, k_Integer]:=
    With[{lg = Length[elements]},
      IntegerDigits[#,lg,k]& /@ Range[0,lg^k-1] /. Thread[
          Range[0,lg-1] -> elements]];

Example :

0% de pub! Que du bonheur et des vrais adhérents !
Vous aussi inscrivez-vous sans plus tarder!!
Message posté à partir de, BBS actif depuis 1995.

  • Prev by Date: Relaunch of Mathematica in Education & Research
  • Next by Date: Re: Assigning elements to a matrix
  • Previous by thread: Re: All combinations
  • Next by thread: Re: All combinations