MathGroup Archive 2002

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

Search the Archive

Re: Generate all k-tuples

  • To: mathgroup at smc.vnet.net
  • Subject: [mg36234] Re: Generate all k-tuples
  • From: "Allan Hayes" <hay at haystack.demon.co.uk>
  • Date: Tue, 27 Aug 2002 02:07:57 -0400 (EDT)
  • References: <akcp10$52r$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Bob,

    KTuples[n_,lst_]:= Distribute[Table[{a,b},{n}],List]

    KTuples[3,{a,b}]

        {{a,a,a},{a,a,b},{a,b,a},{a,b,b},{b,a,a},{b,a,b},{b,b,a},{b,b,b}}

--
Allan

---------------------
Allan Hayes
Mathematica Training and Consulting
Leicester UK
www.haystack.demon.co.uk
hay at haystack.demon.co.uk
Voice: +44 (0)116 271 4198
Fax: +44 (0)870 164 0565


"Bob" <rdobrow at carleton.edu> wrote in message
news:akcp10$52r$1 at smc.vnet.net...
> 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: Functions with vector arguments
  • Next by Date: RE: Functions with vector arguments
  • Previous by thread: RE: Generate all k-tuples
  • Next by thread: Re: Generate all k-tuples