Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions DIRECTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,7 @@
* [Decimal To Fraction](maths/decimal_to_fraction.py)
* [Derangement](maths/derangement.py)
* [Digital Root](maths/digital_root.py)
* [Disarium](maths/disarium.py)
* [Dodecahedron](maths/dodecahedron.py)
* [Double Factorial](maths/double_factorial.py)
* [Dual Number Automatic Differentiation](maths/dual_number_automatic_differentiation.py)
Expand Down
24 changes: 24 additions & 0 deletions maths/disarium.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
def is_disarium(num: int) -> bool:
"""
Check if a number is Disarium.

https://rosettacode.org/wiki/Disarium_numbers

>>> is_disarium(89)
True
>>> is_disarium(75)
False
>>> is_disarium(135)
True
"""
digits = list(str(num))
total = 0
for i in range(len(digits)):
total += int(digits[i]) ** (i + 1)
return total == num


if __name__ == "__main__":
import doctest

doctest.testmod(verbose=True)
Loading