MathGroup Archive 1999

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

Search the Archive

Re: How to construct all possible orderings

  • To: mathgroup at smc.vnet.net
  • Subject: [mg15647] Re: [mg15588] How to construct all possible orderings
  • From: BobHanlon at aol.com
  • Date: Sat, 30 Jan 1999 04:28:43 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

In a message dated 1/28/99 5:42:52 AM, ccarreto at ipg.pt writes:

>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
>
>How can I do this? 
>

Carlos,

orderings[x_?VectorQ] := Module[{len = Length[x]},
		 Flatten[Outer[List,Sequence @@ Table[x, {len}]], 
			len-1]]

orderings[{A, B, C}]

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

Table[{len = Length[orderings[Range[k]]], len == k^k}, 
		{k, 6}]

{{1, True}, {4, True}, {27, True}, {256, True}, 
  {3125, True}, {46656, True}}


Bob Hanlon


  • Prev by Date: RE: Bug in Det[ ], once more
  • Next by Date: Re: Block vs. Module
  • Previous by thread: Re: How to construct all possible orderings
  • Next by thread: Re: How to construct all possible orderings