From 1de9ed7687788669b2fea1f77658fc8dedb3eac5 Mon Sep 17 00:00:00 2001 From: VarunArora24 Date: Sat, 18 Oct 2025 16:20:45 +0530 Subject: [PATCH 1/4] Added a program to check whether a number is disarium or not --- maths/special_numbers/disarium_number.py | 27 ++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 maths/special_numbers/disarium_number.py diff --git a/maths/special_numbers/disarium_number.py b/maths/special_numbers/disarium_number.py new file mode 100644 index 000000000000..565a7676576b --- /dev/null +++ b/maths/special_numbers/disarium_number.py @@ -0,0 +1,27 @@ +def is_disarium(num): + """ + Check if a number is a Disarium number. + A Disarium number is a number in which the sum of its digits + powered with their respective positions is equal to the number itself. + + Example: + 135 -> 1¹ + 3² + 5³ = 135 ✅ + """ + digits = str(num) + total = 0 + position = 1 + + for i in digits: + total += int(i) ** position + position += 1 + + if total == num: + return True + else: + return False + + +if __name__ == "__main__": + test_numbers = [89, 135, 175, 518, 9, 10] + for n in test_numbers: + print(f"{n} → {'Disarium' if is_disarium(n) else 'Not Disarium'}") From ccbd0d2fe39a162afe6f45837d7d1c41df8a9e93 Mon Sep 17 00:00:00 2001 From: VarunArora24 Date: Sat, 18 Oct 2025 16:50:08 +0530 Subject: [PATCH 2/4] Fixed the return statement and improved syntax --- maths/special_numbers/disarium_number.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/maths/special_numbers/disarium_number.py b/maths/special_numbers/disarium_number.py index 565a7676576b..8264f9ba8637 100644 --- a/maths/special_numbers/disarium_number.py +++ b/maths/special_numbers/disarium_number.py @@ -15,10 +15,7 @@ def is_disarium(num): total += int(i) ** position position += 1 - if total == num: - return True - else: - return False + return total == num if __name__ == "__main__": From 626c456bafe5d6ce7066242e96fe1f942b248e8d Mon Sep 17 00:00:00 2001 From: VarunArora24 Date: Sat, 18 Oct 2025 17:20:47 +0530 Subject: [PATCH 3/4] Add type hints and doctests for is_disarium function --- maths/special_numbers/disarium_number.py | 27 +++++++++++++++++------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/maths/special_numbers/disarium_number.py b/maths/special_numbers/disarium_number.py index 8264f9ba8637..dc890db4869f 100644 --- a/maths/special_numbers/disarium_number.py +++ b/maths/special_numbers/disarium_number.py @@ -1,11 +1,25 @@ -def is_disarium(num): +def is_disarium(num: int) -> bool: """ Check if a number is a Disarium number. + A Disarium number is a number in which the sum of its digits powered with their respective positions is equal to the number itself. - Example: - 135 -> 1¹ + 3² + 5³ = 135 ✅ + Args: + num (int): The number to check. + + Returns: + bool: True if num is a Disarium number, False otherwise. + + Examples: + >>> is_disarium(135) + True + >>> is_disarium(89) + True + >>> is_disarium(75) + False + >>> is_disarium(9) + True """ digits = str(num) total = 0 @@ -16,9 +30,6 @@ def is_disarium(num): position += 1 return total == num - - if __name__ == "__main__": - test_numbers = [89, 135, 175, 518, 9, 10] - for n in test_numbers: - print(f"{n} → {'Disarium' if is_disarium(n) else 'Not Disarium'}") + import doctest + doctest.testmod() From cc4918c645d986c90229dbb5496917c4fc80dde7 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 18 Oct 2025 11:51:20 +0000 Subject: [PATCH 4/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- maths/special_numbers/disarium_number.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/maths/special_numbers/disarium_number.py b/maths/special_numbers/disarium_number.py index dc890db4869f..4cd72bdb074e 100644 --- a/maths/special_numbers/disarium_number.py +++ b/maths/special_numbers/disarium_number.py @@ -30,6 +30,9 @@ def is_disarium(num: int) -> bool: position += 1 return total == num + + if __name__ == "__main__": import doctest + doctest.testmod()