RosettaCodeData/Task/Permutations/Quackery/permutations-1.quackery
2023-07-01 13:44:08 -04:00

32 lines
835 B
Text

[ stack ] is perms.min ( --> [ )
[ stack ] is perms.max ( --> [ )
forward is (perms)
[ over size
perms.min share > if
[ over temp take
swap nested join
temp put ]
over size
perms.max share < if
[ dup size times
[ 2dup i^ pluck
rot swap nested join
swap (perms) ] ]
2drop ] resolves (perms) ( [ [ --> )
[ perms.max put
1 - perms.min put
[] temp put
[] swap (perms)
temp take
perms.min release
perms.max release ] is perms ( [ a b --> [ )
[ dup size dup perms ] is permutations ( [ --> [ )
' [ 1 2 3 ] permutations echo cr
$ "quack" permutations 60 wrap$
$ "quack" 3 4 perms 46 wrap$