forked from ruppysuppy/Daily-Coding-Problem-Solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path070.py
More file actions
30 lines (22 loc) · 614 Bytes
/
070.py
File metadata and controls
30 lines (22 loc) · 614 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
"""
Problem:
Given a positive integer n, return the n-th perfect number.
For example, given 1, you should return 19. Given 2, you should return 28.
"""
def calc_sum_of_digits(num: int) -> int:
s = 0
for digit in str(num):
s += int(digit)
return s
def get_nth_perfect_num_naive(n: int) -> int:
num = 19
count = 1
while n > count:
num += 1
if calc_sum_of_digits(num) == 10:
count += 1
return num
if __name__ == "__main__":
print(get_nth_perfect_num_naive(1))
print(get_nth_perfect_num_naive(2))
print(get_nth_perfect_num_naive(10))