MathGroup Archive 2002

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

Search the Archive

Re: Generate all k-tuples

  • To: mathgroup at smc.vnet.net
  • Subject: [mg36222] Re: [mg36181] Generate all k-tuples
  • From: Rob Pratt <rpratt at email.unc.edu>
  • Date: Tue, 27 Aug 2002 02:07:32 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

On Mon, 26 Aug 2002, Bob wrote:

> Is there an easy (elegant?) way to generate the set of all k-tuples
> taking values from some set (list) S? I want the arguments of the
> function to be k (the length of the tuples) and the set S. That is,
> KTuples[3,{a,b}] should produce
> {{a,a,a},{a,a,b},{a,b,a},{a,b,b},{b,a,a},{b,a,b},{b,b,a},{b,b,b}}.

Method 1:

Distribute[Table[{a,b},{3}],List]


Method 2:

Needs["DiscreteMath`Combinatorica`"];
Strings[{a,b},3]


Rob Pratt
Department of Operations Research
The University of North Carolina at Chapel Hill

rpratt at email.unc.edu

http://www.unc.edu/~rpratt/



  • Prev by Date: RE: Generate all k-tuples
  • Next by Date: Can you help me to solve this Integrate using Mathematica ?
  • Previous by thread: RE: Generate all k-tuples
  • Next by thread: Re: Generate all k-tuples