From: andrews on
Hi,
I am looking at a algoritm for special permutation with integers like
f.e.
I start with 1,2,3,4,5

and I want the result

1 2 3 4 5
2 3 5 1 4
4 1 2 5 3
5 4 1 3 2
3 5 4 2 1

Some subset where al of the numbers are on different places

Thanks for any response


From: Family Tree Mike on
On 4/17/2010 3:46 AM, andrews wrote:
> Hi,
> I am looking at a algoritm for special permutation with integers like
> f.e.
> I start with 1,2,3,4,5
>
> and I want the result
>
> 1 2 3 4 5
> 2 3 5 1 4
> 4 1 2 5 3
> 5 4 1 3 2
> 3 5 4 2 1
>
> Some subset where al of the numbers are on different places
>
> Thanks for any response
>
>

The algorithm would be to take each of the items as the starting
element, and pass the remainders as a shorter list to find the
permutations of the shorter list. Take a smaller set, {1, 2, 3}.
Basically, you would keep the {1}, and pass {2, 3} to the permutations
to find the smaller lists permutations {2, 3} and {3, 2}. Now in the
caller you stick those two lists to the back end of {1}, so you have {1,
2, 3}, and {1, 3, 2}. Now you do the same with {2}, appending {1, 3}
and {3, 1}, and {3} appending {1, 2} and {2, 1}. You could implement
the algorithm using recursion, ending the recursion when the size of the
list passed in is one.

--
Mike