ehr_gen

Function ehr_gen 

Source
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 parameter n represents the number of elements in the permutation. In the given example, n is 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, ["๐Ÿ", "๐ŸŒ", "๐Ÿ‡", "๐Ÿ‰"]);