loading...

re: Write a script to find "Happy Numbers" VIEW POST

FULL DISCUSSION
 

A simple Rust Solution

fn is_happy(mut n :i32) -> bool {
    let mut sum = 0;

    while n > 0 {
        let a = n%10;
        n = n/10;
        sum += a*a;
    }

    if sum == 1 {
        return true;
    } else if sum == 4 {
        return false
    }
    is_happy(sum)
}
Code of Conduct Report abuse