MathGroup Archive 1999

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

Search the Archive

All possible orderings of ABC.

  • To: mathgroup at smc.vnet.net
  • Subject: [mg15689] All possible orderings of ABC.
  • From: "Alan W.Hopper" <awhopper at hermes.net.au>
  • Date: Mon, 1 Feb 1999 14:54:10 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

Concerning Carlos Carreto's original message ;

>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


Stephen Luttrell states ;

>I suspect that there might be a clever routine in
>DiscreteMath`Combinatorica` that does this directly, but I can't find
>it.

What about ;

In[3]:= <<DiscreteMath`Combinatorica`

In[4]:=
Strings[{A,B,C},3]

Out[4]=
{{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}}

In[5]:=
Length[%]

Out[5]=
27

But don't try to use the built-in String or StringForm, etc, for this 
result.

--------------------

Alan Hopper

Katoomba, Australia.




  • Prev by Date: Re: Mathematica and OPENSTEP
  • Next by Date: Programming the front end to save graphics files
  • Previous by thread: Re: Mathematica and OPENSTEP
  • Next by thread: Programming the front end to save graphics files