MathGroup Archive 2002

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

Search the Archive

RE: Generate all k-tuples

  • To: mathgroup at smc.vnet.net
  • Subject: [mg36212] RE: [mg36181] Generate all k-tuples
  • From: "DrBob" <drbob at bigfoot.com>
  • Date: Tue, 27 Aug 2002 02:07:19 -0400 (EDT)
  • Reply-to: <drbob at bigfoot.com>
  • Sender: owner-wri-mathgroup at wolfram.com

kTuples[k_Integer?Positive, s_List] := Partition[Flatten@Outer[List,
Sequence @@ (s & /@ Range[k])], k]
kTuples[3, {a, b}]

Bobby Treat

-----Original Message-----
From: Bob [mailto:rdobrow at carleton.edu] 
To: mathgroup at smc.vnet.net
Subject: [mg36212] [mg36181] Generate all k-tuples

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





  • Prev by Date: RE: Variable functions
  • Next by Date: Re: Generate all k-tuples
  • Previous by thread: Re: Generate all k-tuples
  • Next by thread: Re: Generate all k-tuples