Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def perf_happy(n):
- result = []
- bad_numbers = set()
- for i in range(1, n + 1):
- if i in bad_numbers:
- continue
- temp = set()
- z = i
- while True:
- temp_2 = sum([int(x) ** 2 for x in str(z)])
- if temp_2 == 1:
- result.append(i)
- break
- elif temp_2 in temp or temp_2 in bad_numbers:
- bad_numbers.update(temp)
- break
- elif temp_2 not in temp:
- temp.add(temp_2)
- z = temp_2
- return result
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement