Skip to content

Instantly share code, notes, and snippets.

@overloadedargs
Created April 21, 2020 12:47
Show Gist options
  • Save overloadedargs/c83a00078dc3017666f2672618de8f40 to your computer and use it in GitHub Desktop.
Save overloadedargs/c83a00078dc3017666f2672618de8f40 to your computer and use it in GitHub Desktop.
Happy Numbers
def is_happy(n):
while (n != 1):
digits = str(n)
sum = 0
i = 0
print n
while (i < len(digits)):
sum += int(digits[i]) ** 2
i += 1
n = sum
if (n == 1):
return True
print is_happy(7)
print is_happy(19)
print is_happy(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment