A happy number is a number defined by the following process: starting 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.

Those numbers for which this process ends in 1 are **happy numbers**, while those that do not end in 1 are unhappy numbers (or sad numbers) (Wikipedia).

Write a function that takes `n` as parameter and return `true` if and only if `n` is an happy number, `false` otherwise.


## Examples

For example number `7` is happy because after a number of steps the computed sequence ends up with a 1: `7, 49, 97, 130, 10, 1 `

While `3` is not, and would give us an infinite sequence: `3, 9, 81, 65, 61, 37, 58, 89, 145, 42, 20, 4, 16, 37, 58, 89, 145, 42, 20, 4, 16, 37, ...`


Happy coding!

Difficulty: introductory

Starter code:

def is_happy(n):
	

Solutions:
def is_happy(n):
    seen = set()
    while n!=1:
        n = sum(int(d)**2 for d in str(n))
        if n not in seen: seen.add(n)
        else:             return False
    return True

def is_happy(n):
    while n > 4:
        n = sum(int(d)**2 for d in str(n))
    return n == 1


def is_happy(n):
    seen = set()
    
    while n not in seen:
        seen.add(n)
        n = sum( int(d)**2 for d in str(n) )
    
    return n == 1

def is_happy(n):
    seen = set()
    while n > 1 and n not in seen:
        seen.add(n)
        n = sum(int(d)**2 for d in str(n))
    return n == 1

def is_happy(n):
    seen = {n}
    while n != 1:
        n = sum(d*d for d in map(int, str(n)))
        if n in seen:
            return False
        seen.add(n)
    return True

def is_happy(n):
    if n==1:
        return True
    nums=[]
    while n!=1:
        if n in nums:
            return False
        nums.append(n)
        n=sum(int(x)**2 for x in list(str(n)))
        if n==1:
            return True


def is_happy(n):
    if len(str(n))==1:
        return n in [1 , 7]
    else:
        return is_happy(sum([int(d)*int(d) for d in str(n)]))

def is_happy(n):
    lst = []
    while n != 1:
        n = sum(int(i)**2 for i in str(n))
        if n in lst:
            return False
        lst.append(n)
    return True
    # Good Luck!


def is_happy(n):
    while n>=7:
        n = sum(int(x)**2 for x in str(n))
    return n==1