diff --git a/DIRECTORY.md b/DIRECTORY.md index 1552482d70b2..751c47c41e7d 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -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) diff --git a/maths/disarium.py b/maths/disarium.py new file mode 100644 index 000000000000..57040a341de5 --- /dev/null +++ b/maths/disarium.py @@ -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)