permutation ( n seq -- seq' )


Vocabulary
math.combinatorics

Inputs
na non-negative integer
seqa sequence


Outputs
seq'a sequence


Word description
Outputs the nth lexicographical permutation of seq.

Notes
Permutations are 0-based and a bounds error will be thrown if n is larger than seq length factorial 1 -.

Examples
USING: math.combinatorics prettyprint ; 1 { 0 1 2 } permutation .
{ 0 2 1 }

USING: math.combinatorics prettyprint ; 5 { "apple" "banana" "orange" } permutation .
{ "orange" "banana" "apple" }


Definition