Menu
CoddyTech

Armstrong Number

A positive integer is an Armstrong number when it equals the sum of its own digits, each raised to the power of how many digits it has. 153 has three digits and 1^3 + 5^3 + 3^3 = 153, so it is one. Write a function that gets n and returns true if it is an Armstrong number and false otherwise.

Function

isArmstrong(n: integer) → boolean
ninteger
the positive integer to test
Returnsboolean
true when n equals the sum of its digits, each raised to the number of digits

Constraints

  • 1 ≤ n ≤ 109

Examples

Input
n = 153
Output
true
Explanation
153 has 3 digits, so every digit is cubed: 1 + 125 + 27 = 153. The sum gives back the number, so the answer is true.

lock icon+31 hidden tests on Submit

challenge icon

Follow-up

Only 31 Armstrong numbers lie between 1 and 10^9. Can you list all of them without testing a billion numbers one by one?

Reset code
def isArmstrong(n):
    # Write code here
Test cases

Case 1

Case 2

Case 3

Input

n = 153

Expected

true