Expand description
§Derangements
derangements allows you to derange iterables: permutations where no element equals its index
§Examples
use std::collections::HashMap;
use itertools::{assert_equal, Itertools};
use derangements::{derangements, restricted_permutations_by_map_value};
assert_equal(derangements(vec![0usize, 1, 2].into_iter(), 3).sorted(), [[1, 2, 0], [2, 0, 1]]);
// The module also contains other variants of restricted permutations
// Exclude from value 0 from indices 0 and 1, and value 1 from indices 1 and 2.
let restrict = HashMap::from([(0, vec![0, 1]), (1, vec![1, 2])]);
assert_equal(restricted_permutations_by_map_value(vec![0, 1, 2, 3].into_iter(), 3, restrict).sorted(),
[[1, 2, 0], [1, 2, 3], [1, 3, 0], [1, 3, 2], [2, 3, 0], [3, 2, 0]]);Functions§
- derangements
- Derange k or all elements of an iterable.
- derangements_
range - Derange all elements of a range of 0 to n (non-inclusive).
- derangements_
range_ fast - Derange all elements of a range of 0 to n (non-inclusive) with caching.
- distinct_
derangements - Derange k or all elements of an iterable without repetitions.
- distinct_
permutations - Permute k or all elements of an iterable without repetitions.
- fast_
permutations - Permute k or all elements of an iterable.
- restricted_
permutations - Permute k or all elements of an iterable while excluding based on an input restriction
- restricted_
permutations_ by_ map_ index - Permute k or all elements of an iterable while excluding based on an input restriction
- restricted_
permutations_ by_ map_ value - Permute k or all elements of an iterable while excluding based on an input restriction
- restricted_
permutations_ by_ self - Permute k or all elements of an iterable while excluding any results where one of the elements doesn’t change.