Re: Generate all k-tuples
- To: mathgroup at smc.vnet.net
- Subject: [mg36214] Re: [mg36181] Generate all k-tuples
- From: Tomas Garza <tgarza01 at prodigy.net.mx>
- Date: Tue, 27 Aug 2002 02:07:21 -0400 (EDT)
- References: <200208260815.EAA05003@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
In[1]:= ktuples[n_Integer, d_List] := Flatten[Outer[List, Sequence @@ Table[d, {n}]], 2] In[2]:= ktuples[3, {a, b}] Out[2]= {{a, a, a}, {a, a, b}, {a, b, a}, {a, b, b}, {b, a, a}, {b, a, b}, {b, b, a}, {b, b, b}} Tomas Garza Mexico City ----- Original Message ----- From: "Bob" <rdobrow at carleton.edu> To: mathgroup at smc.vnet.net Subject: [mg36214] [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}}. > >
- References:
- Generate all k-tuples
- From: rdobrow@carleton.edu (Bob)
- Generate all k-tuples