User:Oleg Kobchenko/PermRevLexRank

From J Wiki
Jump to navigation Jump to search
  • OEIS:A056019 - Self-inverse infinite permutation which shows the position of each finite permutation's inverse permutation in OEIS:A055089
  • JForum:programming/2007-September/008062 inverse permutation vector
pr=: 3 : 0   NB. PermRevLexRank - unfinished sketch
  r=. - {.y
  for_j.>:i.-<:#y do.
    r=. r + (j - j{y) * !x:j
    y=. ( (j{y) (]-<) (j-1){.y ) , j}.y
  end.
  r
)


   Ai=: A.@/:@(A. i.)~"0
   4 Ai i.!4
0 1 2 4 3 5 6 7 12 18 13 19 8 10 14 20 16 22 9 11 15 21 17 23

Invana.png
viewmat |:(5 Ai i.!5) A. i.5

   ,.|:&.> (2 3 4 #: i.!4) ; (4 3 2 1 #: i.!4) ; (4 Ai i.!4) A. i.4
+-----------------------------------------------+
|0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1|
|0 0 0 0 1 1 1 1 2 2 2 2 0 0 0 0 1 1 1 1 2 2 2 2|
|0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 3|
+-----------------------------------------------+
|0 0 0 0 0 0 1 1 1 1 1 1 2 2 2 2 2 2 3 3 3 3 3 3|
|0 0 1 1 2 2 0 0 1 1 2 2 0 0 1 1 2 2 0 0 1 1 2 2|
|0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1|
|0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0|
+-----------------------------------------------+
|0 0 0 0 0 0 1 1 2 3 2 3 1 1 2 3 2 3 1 1 2 3 2 3|
|1 1 2 3 2 3 0 0 0 0 0 0 2 3 1 1 3 2 2 3 1 1 3 2|
|2 3 1 1 3 2 2 3 1 1 3 2 0 0 0 0 0 0 3 2 3 2 1 1|
|3 2 3 2 1 1 3 2 3 2 1 1 3 2 3 2 1 1 0 0 0 0 0 0|
+-----------------------------------------------+


 0 0 0 0 0 0 1 1 1 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