Re: How to construct all possible orderings
- To: mathgroup at smc.vnet.net
- Subject: [mg15649] Re: How to construct all possible orderings
- From: Paul Abbott <paul at physics.uwa.edu.au>
- Date: Sat, 30 Jan 1999 04:28:44 -0500 (EST)
- Organization: University of Western Australia
- References: <78patb$ctc@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Carlos Carreto wrote: > I am trying to construct all possible orderings of for example 3 > elements, where each element can be A, B or C. > > The result will be something like this: AAA > AAB > AAC > ABA > . . . > CCC Here is one way using Distribute: In[1]:= Distribute[Table[{"A", "B", "C"}, {3}], List] Out[1]= {{"A", "A", "A"}, {"A", "A", "B"}, {"A", "A", "C"}, {"A", "B", "A"}, {"A", "B", "B"}, {"A", "B", "C"}, {"A", "C", "A"}, {"A", "C", "B"}, {"A", "C", "C"}, {"B", "A", "A"}, {"B", "A", "B"}, {"B", "A", "C"}, {"B", "B", "A"}, {"B", "B", "B"}, {"B", "B", "C"}, {"B", "C", "A"}, {"B", "C", "B"}, {"B", "C", "C"}, {"C", "A", "A"}, {"C", "A", "B"}, {"C", "A", "C"}, {"C", "B", "A"}, {"C", "B", "B"}, {"C", "B", "C"}, {"C", "C", "A"}, {"C", "C", "B"}, {"C", "C", "C"}} If you want the result as a text string, you can use StringJoin: In[2]:= Apply[StringJoin, %, {1}] Out[2]= {"AAA", "AAB", "AAC", "ABA", "ABB", "ABC", "ACA", "ACB", "ACC", "BAA", "BAB", "BAC", "BBA", "BBB", "BBC", "BCA", "BCB", "BCC", "CAA", "CAB", "CAC", "CBA", "CBB", "CBC", "CCA", "CCB", "CCC"} Cheers, Paul ____________________________________________________________________ Paul Abbott Phone: +61-8-9380-2734 Department of Physics Fax: +61-8-9380-1014 The University of Western Australia Nedlands WA 6907 mailto:paul at physics.uwa.edu.au AUSTRALIA http://www.physics.uwa.edu.au/~paul God IS a weakly left-handed dice player ____________________________________________________________________