Permutations/Rank of a permutation: Difference between revisions

(Added Quackery.)
Line 1,825:
Stretch goal: The words defined here would handle the limitations of the Stack Exchange question with ease, as Quackery numbers are BigInts. The only inconvenience would be generating random numbers in the range 0 to 144! - 1, as the built-in PRNG is limited to 64 bits.
 
<syntaxhighlight lang="Quackery"> [ 1 swap times [ i 1+ * ] ] is ! ( n --> n )
[ 1 dropswap ]times [ i 1+ * ] ] is ! is perm->rank ( [n --> n )
 
[ [] swap times [ i^ join ] ] is identity ( n --> [ )
 
[ []dup identity unrot 1 - times
[] unrot 1 - times
[ i 1+ ! /mod
dip join ] drop ] is factoradic ( n n --> [ )
Line 1,838 ⟶ 1,840:
swap ]
join ] is inversion ( [ [ --> [ )
[ dup identity unrot
factoradic inversion ] is rank->perm ( n n --> [ )
[ 0 over size identity rot
witheach
[ over find
dup dip [ pluck drop ]
rot i 1+ * + swap ]
drop ] is perm->rank ( [ --> n )
 
[ factoradic inversion ] is rank->perm ( n n --> [ )
3 ! times
 
[ i^
[ 0[] over size identity rot
dup echo say " -> "
3rot rank->permwitheach
dup echo say[ "over -> "find
perm->rank dup dip
echo cr [ pluck drop ]
dup dip [ pluckswap dip dropjoin ]
cr
drop -1 split drop ] is perm->fdic ( [ --> [ )
4 times
 
[ 12 ! random
[ 0 swap
dup echo say " -> "
witheach [ 12+ i 1+ * ] ] is fdic->rank ( [ -->perm n )
 
dup echo say " -> "
[ perm->fdic fdic->rank ] is perm->rank ( [ --> n )
 
echo cr ]</syntaxhighlight>
3 ! times
[ i^
dup echo say " -> "
3 rank->perm
dup echo say " -> "
perm->rank
echo cr ]
cr
4 times
[ 12 ! random
dup echo say " -> "
12 rank->perm
dup echo say " -> "
perm->rank
echo cr ]</syntaxhighlight>
 
{{out}}
Line 1,874 ⟶ 1,881:
5 -> [ 2 1 0 ] -> 5
 
355561581195266704 -> [ 84 10 119 70 11 3 97 4 05 6 2 58 1 2 ] -> 355561581195266704
297516255240729875 -> [ 76 0 4 115 97 10 011 1 23 68 510 89 32 ] -> 297516255240729875
196469317109569601 -> [ 42 119 1 511 96 0 23 64 85 37 10 78 ] -> 196469317109569601
309764555275654445 -> [ 7 9 3 6 810 111 5 7 2 43 111 109 4 8 0 ] -> 309764555275654445
</pre>
 
1,496

edits