[][src]Function permute::permute

pub fn permute<T: Clone>(values: Vec<T>) -> Vec<Vec<T>>

Generate permutations of a given Vec by copying.

Complexity

This function is O(n!) in both memory and time.

Determinism

The order of the permutations is deterministic and can be found ahead of time by consulting the OEIS sequence for reverse colexicographic ordering, using the appropriate elements of A280318 as indices into A055089.

Examples

assert_eq!(
    permute(vec![1, 2, 3]),
    vec![
        vec![1, 2, 3],
        vec![2, 1, 3],
        vec![3, 1, 2],
        vec![1, 3, 2],
        vec![2, 3, 1],
        vec![3, 2, 1]
    ]
);