1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/// Calculate Greatest Common Divisor (GCD), using Euclides' algorithm pub fn gcd(x: i32, y: i32) -> i32 { // Store the highest in a, the lowest in b let (mut a, mut b) = { if x > y { (x, y) } else { (y, x) } }; while b != 0 { let r = a % b; a = b; b = r; } a }