tasks a-s
This commit is contained in:
parent
47bf37c096
commit
b83f433714
12433 changed files with 156208 additions and 123 deletions
6
Task/Permutations/GAP/permutations-1.gap
Normal file
6
Task/Permutations/GAP/permutations-1.gap
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
gap>perms := n -> List(SymmetricGroup(n), p -> List([1..n], x -> x^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