Mathematica 9 is now available
Services & Resources / Wolfram Forums
MathGroup Archive
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2006

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

Search the Archive

Re: Word permutations - frustrated by lists.

  • To: mathgroup at
  • Subject: [mg71728] Re: Word permutations - frustrated by lists.
  • From: "dimitris" <dimmechan at>
  • Date: Mon, 27 Nov 2006 04:05:25 -0500 (EST)
  • References: <ekbrks$jga$>

There is a very simple way to work:

permstr[x_String] := Permutations[Characters[x]]


{{"d", "e", "a", "r"}, {"d", "e", "r", "a"}, {"d", "a", "e", "r"},
{"d", "a", "r", "e"}, {"d", "r", "e", "a"},
  {"d", "r", "a", "e"}, {"e", "d", "a", "r"}, {"e", "d", "r", "a"},
{"e", "a", "d", "r"}, {"e", "a", "r", "d"},
  {"e", "r", "d", "a"}, {"e", "r", "a", "d"}, {"a", "d", "e", "r"},
{"a", "d", "r", "e"}, {"a", "e", "d", "r"},
  {"a", "e", "r", "d"}, {"a", "r", "d", "e"}, {"a", "r", "e", "d"},
{"r", "d", "e", "a"}, {"r", "d", "a", "e"},
  {"r", "e", "d", "a"}, {"r", "e", "a", "d"}, {"r", "a", "d", "e"},
{"r", "a", "e", "d"}}


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: Re: Re: 1`2 == 1*^-10
  • Next by Date: Re: Limit of Infinitely Nested Expression (4.0 succeeds, 5.2 fails...)
  • Previous by thread: Word permutations - frustrated by lists.
  • Next by thread: Re: Word permutations - frustrated by lists.