Re: Word permutations - frustrated by lists.

*To*: mathgroup at smc.vnet.net*Subject*: [mg71703] Re: Word permutations - frustrated by lists.*From*: Bill Rowe <readnewsciv at sbcglobal.net>*Date*: Mon, 27 Nov 2006 04:04:13 -0500 (EST)

On 11/26/06 at 5:49 AM, wookiz at hotmail.com (wooks) wrote: >I seem to have a general problem with results that look right but >for embedded lists. Here is an example of my problem. This is >supposed to be a algorithm to generate all permutations of a string. >T >Clear[arrangements] >arrangements[str_String /; StringLength[str] == 1] := {str}; >arrangements[str_String] := (Prepend[arrangements[StringJoin[ >Rest[#]]]], First[#]) & /@ >NestList[RotateRight, Characters[str], StringLength[str] - 1]; >arrangements["dear"] Here is a one line solution StringJoin@@@Permutations[Characters@str] For example In[4]:= StringJoin@@@Permutations[Characters@"cat"] Out[4]= {cat,cta,act,atc,tca,tac} -- To reply via email subtract one hundred and four