Happy Number

MATH

Problem

Given a number num, determine if it is a happy number.

A 'happy' number is defined as follows: Start with any positive integer, replace the number by the sum of the squares of its digits, and repeat the process until the number equals 1 (where it will stay), or it loops endlessly in a cycle which does not include 1.

Examples

isHappyNumber(7) // returns true // 7^2 -> 49 // 4^2 + 9^2 -> 97 // 9^2 + 7^2 -> 130 // 1^2 + 3^2 + 0^2 -> 10 // 1^2 + 0^2 = 1. isHappyNumber(11) // returns false // Squaring and summing the digits of 11 does not lead to 1
Loading...