Skip to content

Commit 3f9ec25

Browse files
committed
Add Python function to check Disarium numbers
1 parent c79034c commit 3f9ec25

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

maths/disarium.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
def is_disarium(num: int) -> bool:
2+
"""
3+
Check if a number is Disarium.
4+
5+
>>> is_disarium(89)
6+
True
7+
>>> is_disarium(75)
8+
False
9+
>>> is_disarium(135)
10+
True
11+
"""
12+
digits = list(str(num))
13+
total = 0
14+
for i in range(len(digits)):
15+
total += int(digits[i]) ** (i + 1)
16+
return total == num
17+
18+
19+
if __name__ == "__main__":
20+
import doctest
21+
doctest.testmod(verbose=True)

0 commit comments

Comments
 (0)