all-combinations ( seq k -- seq' ) (original) (raw)

all-combinations ( seq k -- seq' )

Vocabulary
math.combinatorics

Inputs

seq a sequence
k a non-negative integer

Outputs

seq' a sequence

Word description
Outputs a sequence containing all combinations of seq choosing k elements, in lexicographical order.

Examples

USING: math.combinatorics prettyprint ; { "a" "b" "c" "d" } 2 all-combinations .
{ { "a" "b" } { "a" "c" } { "a" "d" } { "b" "c" } { "b" "d" } { "c" "d" } }

Definition

IN: math.combinatorics

: all-combinations ( seq k -- seq' ) [ ] map-combinations ;