Skip to content

Commit 4df05f4

Browse files
committed
Add disarium.py file
1 parent c79034c commit 4df05f4

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

maths/disarium.py

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

0 commit comments

Comments
 (0)