combination-indices ( x! p n -- seq )


Vocabulary
math.combinatorics.private

Inputs
x!an object
pan object
nan object


Outputs
seqan object


Definition


:: combination-indices ( x! p n -- seq )
x 1 + x! p 0 <array> :> c 0 :> k! 0 :> r! p 1 - [| i |
i [ 0 ] [ 1 - c nth-unsafe ] if-zero i c set-nth-unsafe
[ k x < ] [
i c [ 1 + ] change-nth-unsafe n i c nth-unsafe -
p i 1 + - nCk r! k r + k!
] do while k r - k!
] each-integer p 2 < [ 0 ] [ p 2 - c nth-unsafe ] if p 1 <
[ drop ] [ x + k - p 1 - c set-nth-unsafe ] if c
[ 1 - ] map! ;