Permutations: Difference between revisions
Content added Content deleted
m (→{{header|GAP}}: slightly simpler) |
|||
Line 1,304:
=={{header|GAP}}==
GAP can handle permutations and groups. Here is a straightforward implementation : for each permutation p in S(n) (symmetric group),
compute the images of 1 ..
which would probably be more manageable in later computations.
<lang gap>gap>
perms(4);
[ [ 1, 2, 3, 4 ], [ 4, 2, 3, 1 ], [ 2, 4, 3, 1 ], [ 3, 2, 4, 1 ], [ 1, 4, 3, 2 ], [ 4, 1, 3, 2 ], [ 2, 1, 3, 4 ],
Line 1,313:
[ 4, 3, 2, 1 ], [ 2, 3, 4, 1 ], [ 3, 4, 2, 1 ] ]</lang>
GAP has also built-in functions to get permutations
<lang gap># All arrangements of 4 elements in 1 .. 4
Arrangements([1 .. 4], 4);
# All permutations of 1 .. 4
PermutationsList([1 .. 4]);</lang>
Here is an implementation using a function to compute next permutation in lexicographic order:
<lang gap>NextPermutation := function(a)
|