From 4b720f4dbeef08fc4b9e886d40f5ced34e798387 Mon Sep 17 00:00:00 2001 From: Sayamgarg1 Date: Sun, 7 Dec 2025 14:33:33 +0530 Subject: [PATCH 1/2] Create is_armstrong.py --- maths/is_armstrong.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 maths/is_armstrong.py diff --git a/maths/is_armstrong.py b/maths/is_armstrong.py new file mode 100644 index 000000000000..8f8618c46bda --- /dev/null +++ b/maths/is_armstrong.py @@ -0,0 +1,20 @@ +def is_armstrong(n: int) -> bool: + """ + Check if a number is an Armstrong number. + + An Armstrong number (Narcissistic number) is a number that is equal + to the sum of its digits each raised to the power of the number of digits. + + Example: + 153 = 1^3 + 5^3 + 3^3 + """ + + digits = list(map(int, str(n))) + num_digits = len(digits) + return n == sum(d ** num_digits for d in digits) + + +if __name__ == "__main__": + print(is_armstrong(153)) # True + print(is_armstrong(370)) # True + print(is_armstrong(10)) # False From 53056f7bd8e9b6618d2296c484f4cae97117d7b4 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 7 Dec 2025 09:08:22 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- maths/is_armstrong.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/maths/is_armstrong.py b/maths/is_armstrong.py index 8f8618c46bda..dc4186add066 100644 --- a/maths/is_armstrong.py +++ b/maths/is_armstrong.py @@ -11,10 +11,10 @@ def is_armstrong(n: int) -> bool: digits = list(map(int, str(n))) num_digits = len(digits) - return n == sum(d ** num_digits for d in digits) + return n == sum(d**num_digits for d in digits) if __name__ == "__main__": print(is_armstrong(153)) # True print(is_armstrong(370)) # True - print(is_armstrong(10)) # False + print(is_armstrong(10)) # False