Permutations/Rank of a permutation: Difference between revisions

Content added Content deleted
(Added Quackery.)
Line 1,825: 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.
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 )
<syntaxhighlight lang="Quackery">
[ 1 swap times [ i 1+ * ] ] is ! ( n --> n )


[ [] swap times [ i^ join ] ] is identity ( n --> [ )
[ [] swap times [ i^ join ] ] is identity ( n --> [ )

[ [] unrot 1 - times
[ dup identity unrot
[] unrot 1 - times
[ i 1+ ! /mod
[ i 1+ ! /mod
dip join ] drop ] is factoradic ( n n --> [ )
dip join ] drop ] is factoradic ( n n --> [ )
Line 1,838: Line 1,840:
swap ]
swap ]
join ] is inversion ( [ [ --> [ )
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^
[ [] over size identity
dup echo say " -> "
3 rank->perm
rot witheach
dup echo say " -> "
[ over find
perm->rank
dup dip
echo cr ]
[ pluck drop ]
swap dip join ]
cr
drop -1 split drop ] is perm->fdic ( [ --> [ )
4 times

[ 12 ! random
[ 0 swap
dup echo say " -> "
12 rank->perm
witheach [ + i 1+ * ] ] is fdic->rank ( [ --> n )

dup echo say " -> "
perm->rank
[ 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}}
{{out}}
Line 1,874: Line 1,881:
5 -> [ 2 1 0 ] -> 5
5 -> [ 2 1 0 ] -> 5


355561581 -> [ 8 10 11 7 3 9 4 0 6 2 5 1 ] -> 355561581
195266704 -> [ 4 10 9 0 11 3 7 5 6 8 1 2 ] -> 195266704
297516255 -> [ 7 4 11 9 10 0 1 2 6 5 8 3 ] -> 297516255
240729875 -> [ 6 0 4 5 7 11 1 3 8 10 9 2 ] -> 240729875
196469317 -> [ 4 11 1 5 9 0 2 6 8 3 10 7 ] -> 196469317
109569601 -> [ 2 9 1 11 6 0 3 4 5 7 10 8 ] -> 109569601
309764555 -> [ 7 9 3 6 8 1 5 2 4 11 10 0 ] -> 309764555
275654445 -> [ 6 10 11 5 7 2 3 1 9 4 8 0 ] -> 275654445
</pre>
</pre>