next-permutation ( seq -- seq ) (original) (raw)

next-permutation ( seq -- seq )

Vocabulary
math.combinatorics

Inputs

seq a sequence

Outputs

seq a sequence

Word description
Rearranges the elements in seq into the lexicographically next greater permutation of elements.

Notes
Performs an in-place modification of seq.

Examples

USING: math.combinatorics prettyprint ; "ABC" next-permutation .
"ACB"

Definition

USING: kernel math.combinatorics.private sequences ;

IN: math.combinatorics

: next-permutation ( seq -- seq )
dup empty? [ (next-permutation) ] unless ;