DEV Community

Discussion on: Write a script to find "Happy Numbers"

Collapse
 
iss0iss0 profile image
Jan

Here is my C# implementation:

private static bool IsHappy(int n)
{
    var u = n
        .ToString()
        .Select(c => int.Parse(c.ToString()))
        .Sum(d => d * d);

    if (u == 1) return true;
    if (u == 4) return false;
    return IsHappy(u);
}