Permutations/Rank of a permutation: Difference between revisions
Permutations/Rank of a permutation (view source)
Revision as of 19:02, 10 November 2022
, 1 year ago→{{header|Quackery}}: refactored
(Added Quackery.) |
(→{{header|Quackery}}: refactored) |
||
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">
[ [] swap times [ i^ join ] ] is identity ( n --> [ )
[
[] unrot 1 - times
[ i 1+ ! /mod
dip join ] drop ] is factoradic ( n n --> [ )
Line 1,838 ⟶ 1,840:
swap ]
join ] is inversion ( [ [ --> [ )
factoradic inversion ] is rank->perm ( n n --> [ )▼
[ 0 over size identity rot▼
dup dip [ pluck drop ]▼
▲ drop ] is perm->rank ( [ --> n )
3 ! times▼
[ i^▼
dup echo say " -> "▼
cr▼
drop -1 split drop ] is perm->fdic ( [ --> [ )
4 times▼
[ 12 ! random▼
[ 0 swap
dup echo say " -> "▼
witheach [
dup echo say " -> "▼
[ perm->fdic fdic->rank ] is perm->rank ( [ --> n )
echo cr ]</syntaxhighlight>▼
3 rank->perm
perm->rank
echo cr ]
12 rank->perm
dup echo say " -> "
perm->rank
{{out}}
Line 1,874 ⟶ 1,881:
5 -> [ 2 1 0 ] -> 5
</pre>
|