Permutations/Rank of a permutation: Difference between revisions
Content added Content deleted
(Added Quackery.) |
(→{{header|Quackery}}: refactored) |
||
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"> |
<syntaxhighlight lang="Quackery"> |
||
⚫ | |||
[ [] swap times [ i^ join ] ] is identity ( n --> [ ) |
[ [] swap times [ i^ join ] ] is identity ( n --> [ ) |
||
[ |
[ 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 |
|||
⚫ | |||
⚫ | |||
witheach |
|||
[ over find |
|||
⚫ | |||
rot i 1+ * + swap ] |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
rot witheach |
|||
[ over find |
|||
dup dip |
|||
[ pluck drop ] |
|||
⚫ | |||
⚫ | |||
drop -1 split drop ] is perm->fdic ( [ --> [ ) |
|||
⚫ | |||
⚫ | |||
[ 0 swap |
|||
⚫ | |||
witheach [ + i 1+ * ] ] is fdic->rank ( [ --> n ) |
|||
⚫ | |||
perm->rank |
[ perm->fdic fdic->rank ] is perm->rank ( [ --> n ) |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
3 rank->perm |
|||
⚫ | |||
perm->rank |
|||
echo cr ] |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
12 rank->perm |
|||
dup echo say " -> " |
|||
perm->rank |
|||
⚫ | |||
{{out}} |
{{out}} |
||
Line 1,874: | Line 1,881: | ||
5 -> [ 2 1 0 ] -> 5 |
5 -> [ 2 1 0 ] -> 5 |
||
195266704 -> [ 4 10 9 0 11 3 7 5 6 8 1 2 ] -> 195266704 |
|||
240729875 -> [ 6 0 4 5 7 11 1 3 8 10 9 2 ] -> 240729875 |
|||
109569601 -> [ 2 9 1 11 6 0 3 4 5 7 10 8 ] -> 109569601 |
|||
275654445 -> [ 6 10 11 5 7 2 3 1 9 4 8 0 ] -> 275654445 |
|||
</pre> |
</pre> |
||