re: Project Euler #5 - Finding the Smallest Multiple VIEW POST

FULL DISCUSSION
 

Rust Solution Playground

fn main() {
    println!("{}", get_number(1, 20))
}

fn get_number(start: usize, end: usize) -> u32 {
    (start..end).fold(1_u32, |acc, n| lcm(acc, n as u32))
}

fn lcm(a: u32, b: u32) -> u32 {
    (a * b) / gcd(a, b)
}

fn gcd(a: u32, b: u32) -> u32 {
    if b == 0 {
        a
    } else {
        gcd(b, a % b)
    }
}
code of conduct - report abuse