Skip to content

Instantly share code, notes, and snippets.

@davidbj
Created March 3, 2016 10:59
Show Gist options
  • Select an option

  • Save davidbj/02ff85f36bddd4f87519 to your computer and use it in GitHub Desktop.

Select an option

Save davidbj/02ff85f36bddd4f87519 to your computer and use it in GitHub Desktop.
python happy number demo.
def happy_num(num):
st = set()
while True:
if num == 1:
return True
num = sum([int(i)**2 for i in str(num)])
if num in st:
return False
st.add(num)
def fn():
happy_num_lst = set()
for i in range(10000):
if happy_num(i):
happy_num_lst.add(i)
return happy_num_lst
fn()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment