Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def perf_happy(n):
- result = []
- bad_numbers = set()
- good_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) * int(x) for x in str(z)])
- if temp_2 == 1 or temp_2 in good_numbers:
- result.append(i)
- good_numbers.update(temp)
- 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