Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
6
Task/Permutations/GAP/permutations-1.gap
Normal file
6
Task/Permutations/GAP/permutations-1.gap
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
gap>List(SymmetricGroup(4), p -> Permuted([1 .. 4], p));
|
||||
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 ],
|
||||
[ 3, 1, 4, 2 ], [ 1, 3, 4, 2 ], [ 4, 3, 1, 2 ], [ 2, 3, 1, 4 ], [ 3, 4, 1, 2 ], [ 1, 2, 4, 3 ], [ 4, 2, 1, 3 ],
|
||||
[ 2, 4, 1, 3 ], [ 3, 2, 1, 4 ], [ 1, 4, 2, 3 ], [ 4, 1, 2, 3 ], [ 2, 1, 4, 3 ], [ 3, 1, 2, 4 ], [ 1, 3, 2, 4 ],
|
||||
[ 4, 3, 2, 1 ], [ 2, 3, 4, 1 ], [ 3, 4, 2, 1 ] ]
|
||||
4
Task/Permutations/GAP/permutations-2.gap
Normal file
4
Task/Permutations/GAP/permutations-2.gap
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
# All arrangements of 4 elements in 1 .. 4
|
||||
Arrangements([1 .. 4], 4);
|
||||
# All permutations of 1 .. 4
|
||||
PermutationsList([1 .. 4]);
|
||||
44
Task/Permutations/GAP/permutations-3.gap
Normal file
44
Task/Permutations/GAP/permutations-3.gap
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
NextPermutation := function(a)
|
||||
local i, j, k, n, t;
|
||||
n := Length(a);
|
||||
i := n - 1;
|
||||
while i > 0 and a[i] > a[i + 1] do
|
||||
i := i - 1;
|
||||
od;
|
||||
j := i + 1;
|
||||
k := n;
|
||||
while j < k do
|
||||
t := a[j];
|
||||
a[j] := a[k];
|
||||
a[k] := t;
|
||||
j := j + 1;
|
||||
k := k - 1;
|
||||
od;
|
||||
if i = 0 then
|
||||
return false;
|
||||
else
|
||||
j := i + 1;
|
||||
while a[j] < a[i] do
|
||||
j := j + 1;
|
||||
od;
|
||||
t := a[i];
|
||||
a[i] := a[j];
|
||||
a[j] := t;
|
||||
return true;
|
||||
fi;
|
||||
end;
|
||||
|
||||
Permutations := function(n)
|
||||
local a, L;
|
||||
a := List([1 .. n], x -> x);
|
||||
L := [ ];
|
||||
repeat
|
||||
Add(L, ShallowCopy(a));
|
||||
until not NextPermutation(a);
|
||||
return L;
|
||||
end;
|
||||
|
||||
Permutations(3);
|
||||
[ [ 1, 2, 3 ], [ 1, 3, 2 ],
|
||||
[ 2, 1, 3 ], [ 2, 3, 1 ],
|
||||
[ 3, 1, 2 ], [ 3, 2, 1 ] ]
|
||||
Loading…
Add table
Add a link
Reference in a new issue