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):
- temp = []
- z = i
- while True:
- temp_2 = sum([int(x) ** 2 for x in str(z)])
- if temp_2 in bad_numbers:
- break
- elif temp_2 in temp:
- bad_numbers.update(set(temp))
- break
- elif temp_2 == 1:
- result.append(i)
- break
- elif temp_2 not in temp:
- temp.append(temp_2)
- z = temp_2
- return result
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement