in reply to Searching for a Permutation Algorithm for nPr where n != r

What you need to do is generate each combination of r items out of n, and for each subset generated, generate all permutations of it.

You may find useful help in the forthcoming volume of Knuth's The Art of Computer Programming. Knuth has preprints of parts of it on his web site. You'll need a postscript viewer (or printer) to look at them.

I transcribed one of the non-recursive permutation algorithms into Perl here.

  • Comment on Re: Searching for a Permutation Algorithm for nPr where n != r