A-M baby
This commit is contained in:
parent
764da6cbbb
commit
db842d013d
19005 changed files with 197040 additions and 7 deletions
11
Task/Happy-numbers/Python/happy-numbers.py
Normal file
11
Task/Happy-numbers/Python/happy-numbers.py
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
>>> def happy(n):
|
||||
past = set()
|
||||
while n <> 1:
|
||||
n = sum(int(i)**2 for i in str(n))
|
||||
if n in past:
|
||||
return False
|
||||
past.add(n)
|
||||
return True
|
||||
|
||||
>>> [x for x in xrange(500) if happy(x)][:8]
|
||||
[1, 7, 10, 13, 19, 23, 28, 31]
|
||||
Loading…
Add table
Add a link
Reference in a new issue