Skip to content

Instantly share code, notes, and snippets.

@lucasrcezimbra
Created September 22, 2016 23:54
Show Gist options
  • Save lucasrcezimbra/bcce56db98e5cf2cd921ddb4b6da169d to your computer and use it in GitHub Desktop.
Save lucasrcezimbra/bcce56db98e5cf2cd921ddb4b6da169d to your computer and use it in GitHub Desktop.
Happy Numbers
def happy(number):
if number < 10:
return number in (1,7)
next_ = sum(int(char) ** 2 for char in str(number))
return happy(next_)
assert all([happy(n) for n in (1, 10, 100, 130, 97)])
assert not all([happy(4) for n in (2,3,4,5,6,8,9)])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment