Handbook
Glossary
<k-permutations> ( seq k -- permutations )
Vocabulary
math
.
combinatorics
Inputs
seq
a
sequence
k
an
integer
Outputs
permutations
a
sequence
Word description
An efficient sequence containing the
k
lexicographical permutations of
seq
.
Definition
USING:
combinators
kernel
math
sequences
;
IN:
math.combinatorics
::
<k-permutations>
( seq k -- permutations )
seq
length
:>
n n k
nPk
:>
len
{
{
[
len
zero?
]
[
{
}
]
}
{
[
n k
=
]
[
seq
<permutations>
]
}
[
len n
factorial
over
/i
k seq
k-permutations
boa
]
}
cond
;