loading...

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

FULL DISCUSSION
 

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);
}
code of conduct - report abuse