wolis has asked for the wisdom of the Perl Monks concerning the following question:

Just read in the discussionss section a request for some un-homework.. so:

Permutations.. all of them!

No matter how many

I want a neat little recursive Perl function (do we call them functions even thos the are sub { }?) which will take a list of things and provide a list of all possible permutations of those things.

So you can't know beforhand how many things in the list and make a boring set of while loops to match.

I'm sure this has been done already but I have been working on this in my spare time.. trying to find a pattern of swapping 2 items in the list each time till all items have occupied all possitions in the list.

Any thoughts?
Any solutions you have prepared earlier?


 ___
/\__\ "What is the world coming to?"
\/__/ www.wolispace.com

Replies are listed 'Best First'.
Re: puzzles and permutations
by Paladin (Vicar) on Sep 03, 2003 at 00:59 UTC
    People do ask this question quite often... one might say frequently.
      Thanks,

      Must be part of the human condition to want to know this..

      I must finally becoming human!

      ___ /\__\ "What is the world coming to?" \/__/ www.wolispace.com
Re: puzzles and permutations
by Anonymous Monk on Sep 03, 2003 at 00:59 UTC