OFFSET
0,3
COMMENTS
PermRevLexRank and PermRevLexUnrank have been modified from the algorithms PermLexRank and PermLexUnrank presented in the book "Combinatorial Algorithms, Generation, Enumeration and Search", by Donald L. Kreher and Douglas R. Stinson.
LINKS
EXAMPLE
E.g. the permutation [2,3,1] is the 4th permutation (counting from 0th, the identity permutation) of A055089, its inverse permutation is [3,1,2] which is 3rd, thus a(4)=3 and a(3)=4.
MAPLE
PermRevLexRank := proc(pp) local p, n, i, j, r; p := pp; n := nops(p); r := 0; for j from n by -1 to 1 do r := r + (((j-p[j])*((j-1)!))); for i from 1 to (j-1) do if(p[i] > p[j]) then p[i] := p[i]-1; fi; od; od; RETURN(r); end;
[seq(PermRevLexRank(convert(invperm(convert(PermRevLexUnrank(j), 'disjcyc')), 'permlist', nops(PermRevLexUnrank(j)))), j=0..200)];
MATHEMATICA
A056019 = Position[Ordering /@ #, #[[#2]]][[1, 1]] - 1 &[Reverse@SortBy[Permutations@Range@Ceiling@InverseFunction[Factorial][# + 1], Reverse], # + 1] &; Array[A056019, 69, 0] (* JungHwan Min, Oct 10 2016 *)
A056019L = Ordering[Ordering /@ Permutations@Range@Ceiling@InverseFunction[Factorial][# + 1]] - 1 &; A056019L[24] (* JungHwan Min, Oct 10 2016 *)
CROSSREFS
KEYWORD
nonn,look
AUTHOR
Antti Karttunen, Jun 08 2000
STATUS
approved