DSA Tracker

Visualize

Armstrong Numbers

Sum each digit cubed, compare to the original

time O(d)space O(1)

A number is an Armstrong number when the sum of its own digits, each raised to the power of the digit count, reconstructs the original number. For 153's three digits, that means summing each digit cubed and checking it lands back on 153.

Details

Animated on: n = 153 — check whether n equals the sum of its own digits, each raised to the digit-count's power.

Problem:Armstrong NumbersEasy

Sum each digit cubed, compare to the original

step 1 / 9

1
[0]
5
[1]
3
[2]

153 has 3 digits: 1, 5, 3. Check whether 1^3 + 5^3 + 3^3 equals 153.

Pseudocode
1FUNCTION isArmstrong(n):
2 digits = the digits of n
3 sum = 0
4 FOR each digit d in digits:
5 add d cubed to sum
6 RETURN true if sum equals n, otherwise false

← / → step · space play · Home restart

Every step in words

Show all 9 steps
  1. 153 has 3 digits: 1, 5, 3. Check whether 1^3 + 5^3 + 3^3 equals 153.
  2. digit = 1.
  3. 1^3 = 1. running sum = 1.
  4. digit = 5.
  5. 5^3 = 125. running sum = 1 + 125 = 126.
  6. digit = 3.
  7. 3^3 = 27. running sum = 126 + 27 = 153.
  8. Sum of cubes = 153, with every digit now processed.
  9. 153 (sum of cubes) === 153 (original number) → true, 153 is an Armstrong number.

Now solve it yourself

Watching is the first half. The second is writing it without the animation.