MathGroup Archive 2002

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

Search the Archive

Re: Generate all k-tuples

  • To: mathgroup at smc.vnet.net
  • Subject: [mg36230] Re: Generate all k-tuples
  • From: Selwyn Hollis <slhollis at earthlink.net>
  • Date: Tue, 27 Aug 2002 02:07:47 -0400 (EDT)
  • References: <akcp10$52r$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Here's my contestant:

<<DiscreteMath`Combinatorica`

KTuples[k_Integer, vals_List] :=
   Union[KSubsets[PadRight[vals, k*Length[vals], vals], k]]

---
Selwyn Hollis


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




  • Prev by Date: RE: Fwd: Fwd: RE: rectangle intersection
  • Next by Date: Re: Obtaining sequences from lists of lists
  • Previous by thread: Re: Generate all k-tuples
  • Next by thread: RE: Generate all k-tuples