easy +10 pts

Armstrong Number Check

Write a function that determines whether a number is an Armstrong number.

An **Armstrong number** (also called a **narcissistic number**) is an integer that is equal to the sum of its own digits each raised to the power of the number of digits. For example: - 153 has 3 digits: 1^3 + 5^3 + 3^3 = 1 + 125 + 27 = 153 → true - 1634 has 4 digits: 1^4 + 6^4 + 3^4 + 4^4 = 1 + 1296 + 81 + 256 = 1634 → true - 123 has 3 digits: 1^3 + 2^3 + 3^3 = 36 ≠ 123 → false Define a function `is_armstrong(n: int) -> bool` that returns `True` if `n` is an Armstrong number, and `False` otherwise. The input `n` is a non-negative integer. For `n = 0`, the function should return `True` (a single digit 0 to the power 1 equals 0).

Constraints

Input is a non-negative integer (0 ≤ n ≤ 10^9). Use integer arithmetic; converting to string is allowed.

Example

>>> is_armstrong(153)
True
>>> is_armstrong(123)
False
>>> is_armstrong(0)
True
10 points ~10 min

Recent Submissions

No submissions yet — hit Run Tests to try!

Hints

Count the number of digits in n.
Extract each digit and raise it to the power of the digit count.
Compare the sum to the original number.
Python 3
All tests passed!
Test Results
Press Ctrl+Enter or click Run Tests to execute your code.