User:Inthar/Code: Difference between revisions

Inthar (talk | contribs)
Inthar (talk | contribs)
Line 729: Line 729:
     // `<<` multiplies the left by two to the power of the right.
     // `<<` multiplies the left by two to the power of the right.
     (u << gcd_exponent_on_two) as i64
     (u << gcd_exponent_on_two) as i64
}
fn gcd_u32(m: u32, n: u32) -> u32 {
let mut x = m;
let mut y = n;
while x != 0 && y != 0 {
if x > y {
x = x % y;
} else {
y = y % x;
}
}
if y == 0 {x} else {y}
}
}


Line 907: Line 894:
// Algorithm from Bulgakova et al, 2023, "On balanced and abelian properties of circular words over a ternary alphabet".
// Algorithm from Bulgakova et al, 2023, "On balanced and abelian properties of circular words over a ternary alphabet".
pub fn christoffel_word(a: u32, b: u32) -> String {
pub fn christoffel_word(a: u32, b: u32) -> String {
     let d = gcd_u32(a, b);
     let d = (gcd(a as i64, b as i64) as u32);
     if d == 1 {
     if d == 1 {
         let mut result : String = String::from("");
         let mut result : String = String::from("");