User:Inthar/Code: Difference between revisions

Inthar (talk | contribs)
Inthar (talk | contribs)
mNo edit summary
Line 843: Line 843:
    }
    }
    (mv_result, balance_result)
    (mv_result, balance_result)
    }
}
/// Return a Christoffel word with `a` x's and `b` y's.
/// 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 {
    let d = gcd(a as i64, b as i64) as u32;
    if d == 1 {
        let mut result : String = String::from("");
        let (mut current_x, mut current_y) = (0u32, 0u32); // Start from the (0,0) vector.
        while current_x < a || current_y < b {
            if (current_y+1)*a <= b * (current_x) { // if making the (0,1) step doesn't lead to going above the line
                current_y += 1; // append the b step and reflect that in the plane vector.
                result.push('y');
            } else {
                current_x += 1;
                result.push('x');
            }
        }
        result
    } else {
        std::iter::repeat(christoffel_word(a/d, b/d)).take(d.try_into().unwrap()).collect::<String>()
     }
     }
}
}