September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
|
|
@ -0,0 +1,23 @@
|
|||
function spermutations(integer p, integer i)
|
||||
-- generate the i'th permutation of [1..p]:
|
||||
-- first obtain the appropriate permutation of [1..p-1],
|
||||
-- then insert p/move it down k(=0..p-1) places from the end.
|
||||
integer k = mod(i-1,2*p)
|
||||
if k>=p then k=2*p-1-k end if
|
||||
sequence res
|
||||
integer parity
|
||||
if p>1 then
|
||||
{res,parity} = spermutations(p-1,floor((i-1)/p)+1)
|
||||
res = res[1..length(res)-k]&p&res[length(res)-k+1..$]
|
||||
else
|
||||
res = {1}
|
||||
end if
|
||||
return {res,iff(and_bits(i,1)?1:-1)}
|
||||
end function
|
||||
|
||||
for p=1 to 4 do
|
||||
printf(1,"==%d==\n",p)
|
||||
for i=1 to factorial(p) do
|
||||
?{i,spermutations(p,i)}
|
||||
end for
|
||||
end for
|
||||
Loading…
Add table
Add a link
Reference in a new issue