pub fn exhaustive_unique_vecs_fixed_length<I: Iterator>(
k: u64,
xs: I,
) -> ExhaustiveUniqueVecsFixedLength<I> ⓘ
Expand description
Generates Vec
s of a given length with elements from a single iterator, such that each
Vec
has no repeated elements.
The source iterator should not repeat any elements, but this is not enforced.
If $k$ is 0, the output length is 1.
If $k$ is nonzero and the input iterator is infinite, the output length is also infinite.
If $k$ is nonzero and the input iterator length is $n$, the output length is $$ (n)_ k = \prod_ {i=0}^{k-1}(n - i) = frac{n!}{(n-k)!}. $$
If $k$ is 0, the output consists of one empty Vec
.
If xs
is empty, the output is also empty, unless $k$ is 0.
§Examples
use itertools::Itertools;
use malachite_base::vecs::exhaustive::exhaustive_unique_vecs_fixed_length;
let xss = exhaustive_unique_vecs_fixed_length(4, 1..=6)
.take(20)
.collect_vec();
assert_eq!(
xss.iter().map(Vec::as_slice).collect_vec().as_slice(),
&[
&[1, 2, 3, 4],
&[1, 2, 3, 5],
&[1, 2, 4, 3],
&[1, 2, 4, 5],
&[1, 3, 2, 4],
&[1, 2, 5, 3],
&[1, 3, 4, 2],
&[1, 3, 4, 5],
&[1, 4, 2, 3],
&[1, 3, 2, 5],
&[1, 4, 3, 2],
&[1, 2, 5, 4],
&[2, 1, 3, 4],
&[1, 3, 5, 2],
&[2, 1, 4, 3],
&[2, 3, 4, 5],
&[2, 3, 1, 4],
&[1, 5, 2, 3],
&[2, 3, 4, 1],
&[1, 4, 2, 5]
]
);