pub fn ehr_gen(n: usize) -> GenBoxed<usize>Expand description
Generate all permutations by star transposition
The ehr_gen function generates all permutations of a given length using the star transposition
algorithm.
Arguments:
n: The parameternrepresents the number of elements in the permutation. In the given example,nis set to 4, so it generates permutations of 4 elements.
Returns:
The function ehr_gen returns a GenBoxed<usize>, which is a boxed generator that yields usize
values.
ยงExamples
use ecgen::ehr_gen;
let mut perm = ["๐", "๐", "๐", "๐"];
let mut cnt = 1;
println!("{}", perm.concat());
for n in ehr_gen(perm.len()) {
perm.swap(0, n);
println!("{}", perm.concat());
cnt += 1;
}
assert_eq!(cnt, 24);
assert_eq!(perm, ["๐", "๐", "๐", "๐"]);