MathGroup Archive 2006

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

Search the Archive

Re: Word permutations - frustrated by lists.



Hi,

the easy way to get permutations is:

<< DiscreteMath`Combinatorica`

Permutations[{"d", "e", "a", "r"}]

Daniel



wooks wrote:

> Hello. Am relatively new with Mathematica.

> 

> 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"]

> 

> PS This is not homework. I'm rewriting some examples from another

> programming book as as practice  for Mathematica.

> 



  • Prev by Date: Re: Mathematica "Interpolation" function
  • Next by Date: Re: Not accepting function as parameter
  • Previous by thread: Re: Word permutations - frustrated by lists.
  • Next by thread: Re: Word permutations - frustrated by lists.