Files
pyDefis/Les nombres heureux.py
Francois JUMELLE 20526d93c8 Initial release
2021-05-03 22:32:40 +02:00

19 lines
349 B
Python

mini = 8962
maxi = 9189
def is_happy(n):
table = list()
while len(str(n))>1:
n = str(sum([int(i)**2 for i in str(n)]))
if n in table:
break
else:
table.append(n)
return n=="1"
solution = list()
for i in range(mini, maxi+1):
if is_happy(i):
solution.append(i)
print(solution)