Check Disarium Number in Python

Beginner
⏱️ 9 min read
📚 Updated: Aug 2026
🎯 3 Code Examples
🚀 Live Preview
Digit sums

What You’ll Learn

A Disarium number equals the sum of its digits each raised to its left-to-right position. This tutorial covers the definition vs Armstrong, a live preview, worked Python examples, edge cases, and complexity.

Definition

Position powers

Leftmost digit uses ^1, next ^2, and so on.

Classic Examples

89, 135

Also every one-digit number 1–9 is Disarium.

Right Peel

% 10 // 10

Start exponent at digit count; decrease each peel.

vs Armstrong

Different rule

Armstrong uses one fixed exponent for every digit.

Live Preview

Try any n

Classify positive integers instantly in the browser.

O(d²)

Basic check

Cache powers to bring a single check closer to O(d).

Introduction

Disarium numbers are positive integers equal to the sum of their digits raised to left-to-right position powers. Classic examples: 89 (81 + 92) and 135 (11 + 32 + 53).

Every one-digit number 1–9 is Disarium because d1 = d. Do not confuse this with Armstrong numbers, which use one shared exponent equal to the digit count.

Why it matters?

It trains digit extraction, positional indexing, and careful comparison with similar “digit power” interview problems.

Key Highlights

Left Positions

Positions start at 1 on the leftmost digit.

Rightmost Highest

When peeling right-to-left, start at exponent k.

1–9 Always

All single-digit positives are Disarium.

Not Armstrong

Different exponent rule — say so in interviews.

In short: if digits are d1…dk from the left, check whether d11 + … + dkk equals n.

📝 Problem & Approach

Given a positive integer n, decide whether it equals its position-power digit sum.

python
# 89  → 8**1 + 9**2 = 89   → yes
# 135 → 1**1 + 3**2 + 5**3 → yes
# 10  → 1**1 + 0**2 = 1    → no

Inputs & Outputs

ItemTypeDescription
nintPositive integer (this page excludes 0 and negatives).
Return / printbool / textTrue if n is Disarium.

Minimal workflow

Pseudocode
function is_disarium(n):  // n > 0
    k = number_of_digits(n)
    sum = 0
    pos = k
    while n > 0:
        digit = n mod 10
        sum += digit ^ pos
        pos -= 1
        n = floor(n / 10)
    return sum == original_n

Method comparison

MethodIdeaNotes
Right peel% 10 / // 10 with descending exponentClassic interview loop
Left-to-right stringEnumerate digits with enumerate(..., 1)Positions match the definition directly
Range scanFilter 1…N with the same helperGreat for listing 1–9 and 89

⚡ Quick Reference

GoalPattern
Digit countlen(str(n))
Last digitn % 10
Drop last digitn //= 10
Power termdigit ** pos
Classic yes89, 135, 1…9
Classic no10 (→ sum 1)

📋 Disarium vs Armstrong vs Digit Sum

Related digit problems — different exponent rules.

Disarium
d_i ^ i

Exponent = left-to-right position

Armstrong
d_i ^ k

Same exponent k for every digit

Digit sum
sum d_i

No powers — just add digits

Interview tip
state the rule

Say positions start at 1 on the left

Context

When This Problem Shows Up

Reach for Disarium checks when positional digit powers matter.

  1. Interview warm-ups

    Tests digit loops and careful indexing.

  2. Contrast with Armstrong

    Great follow-up after learning narcissistic numbers.

  3. Range listing tasks

    Print all Disarium numbers in 1…N for small N.

  4. Teaching powers

    Makes position-dependent exponents concrete with 89 and 135.

  5. Not for zero/negatives by default

    Most lists use positive integers only — say so up front.

Key benefit: one short boolean check that forces clear thinking about digit order and exponents.

🔮 Live Preview

Positive integers only, within JavaScript safe range.

Try 89, 135, 10, or 7.

Live result
Press "Check" to evaluate.

Examples Gallery

Three complete Python programs — single check, range scan, and left-to-right string style. Click View Output to reveal sample console results.

📚 Getting Started

Right-to-left peel with descending exponents.

Example 1 — Single Value Check (89)

Direct and interview-friendly implementation for one input value.

python
def is_disarium(number: int) -> bool:
    if number <= 0:
        return False

    original = number
    digits = len(str(number))
    total = 0

    while number > 0:
        digit = number % 10
        total += digit ** digits
        digits -= 1
        number //= 10

    return total == original


n = 89
if is_disarium(n):
    print(f"{n} is a Disarium number.")
else:
    print(f"{n} is not a Disarium number.")

How It Works

The first peeled digit is the rightmost one, so we start the exponent from the full digit count and decrease each step.

⚡ Range Output

Reuse the helper to filter a beginner interval.

Example 2 — Disarium Numbers from 1 to 100

Prints all Disarium numbers in this range.

python
def is_disarium(num: int) -> bool:
    if num <= 0:
        return False
    original = num
    digits = len(str(num))
    total = 0

    while num > 0:
        digit = num % 10
        total += digit ** digits
        digits -= 1
        num //= 10

    return total == original


print("Disarium numbers in the range 1 to 100:")
for i in range(1, 101):
    if is_disarium(i):
        print(i, end=" ")

How It Works

All one-digit positive numbers are Disarium. In two digits up to 100, only 89 matches.

🔁 Left-to-Right Style

Match the definition directly with string enumeration.

Example 3 — Enumerate Digits from the Left

Positions start at 1 — no descending exponent bookkeeping.

python
def is_disarium_ltr(number: int) -> bool:
    if number <= 0:
        return False
    total = 0
    for pos, ch in enumerate(str(number), start=1):
        total += int(ch) ** pos
    return total == number


for n in (89, 135, 10, 7):
    label = "Disarium" if is_disarium_ltr(n) else "not Disarium"
    print(f"{n}: {label}")

How It Works

enumerate(..., start=1) assigns each digit its left-to-right position, which matches the mathematical definition without reversing exponents.

🧠 How the Algorithm Decides

1

Count digits

Set exponent to total digit count (or walk left-to-right with pos = 1…k).

Setup
2

Peel and add

Raise each digit to its position power and accumulate.

Sum
3

Compare

If the sum equals the original number, it is Disarium.

Decide
=

Yes or no

Equality → Disarium; otherwise not.

🔎 Worked Walkthrough — n = 89

Trace the right-peel method. Digit count k = 2.

Digit peeledExponentTermRunning sum
9 (rightmost)28181
81889

Final sum 89 equals n → Disarium.

Use Cases

Where Disarium checks show up beyond the interview prompt.

1. Interview Warm-Ups

Digit peeling plus positional powers in one problem.

Example: write is_disarium(n).

2. Teaching Powers

Makes 81 + 92 memorable with a famous 89.

Example: chalkboard 89 and 135.

3. Armstrong Contrast

Clarify fixed vs positional exponents.

Example: compare 153 vs 135.

4. Range Filters

List Disarium numbers in a classroom interval.

Example: 1 to 100 → 1…9, 89.

5. Indexing Practice

enumerate(start=1) matches the definition cleanly.

Example: left-to-right string style.

6. Complexity Follow-Ups

Discuss O(d²) vs caching digit powers.

Example: precompute for large ranges.

Pro Tip: say “positions start at 1 on the left” before coding — it prevents exponent off-by-ones.

Advantages

Why this pattern works well in interviews and classwork.

  1. 1. Clear Definition

    Position powers are easy to state on a whiteboard.

  2. 2. Two Valid Styles

    Right peel or left-to-right enumerate both work.

  3. 3. Famous Test Cases

    89 and 135 make verification quick.

  4. 4. Rich Follow-Ups

    Armstrong contrast and complexity caching are natural next questions.

Pro Tip: prefer left-to-right enumeration if you want the code to read exactly like the definition.

Usage Tips

Small habits that keep Disarium solutions interview-ready.

  1. 1. State Positions First

    Say left-to-right indexing starts at 1 before coding.

  2. 2. Keep Original n

    Save a copy before the peel loop mutates the working value.

  3. 3. Spot-Check 89 and 10

    Yes and no cases catch exponent mistakes fast.

  4. 4. Contrast Armstrong

    Mention the fixed-exponent rule so interviewers know you know the difference.

  5. 5. Restrict to Positives

    Document that 0 / negatives are out of scope unless asked.

Pro Tip: if peeling from the right, whisper “start at k” — the rightmost digit always gets the largest exponent.

Common Pitfalls

Mistakes that commonly break Disarium solutions.

  1. 1. Wrong Exponent Direction

    Giving the rightmost digit power 1 when peeling from the right.

    → Start at digit count and decrease.

  2. 2. Confusing with Armstrong

    Using a fixed exponent equal to digit count for every digit.

    → Use position i for digit i from the left.

  3. 3. Overwriting n Before Compare

    Comparing the sum to a mutated working variable.

    → Save original = n first.

  4. 4. Zero-Based Positions

    Using enumerate without start=1.

    → Positions must begin at 1.

  5. 5. Accepting Zero Silently

    Many lists exclude 0; treat it as non-Disarium here.

    → Return False for n ≤ 0 unless the prompt says otherwise.

Edge Cases

Most lists use positive numbers only; be explicit about zero and negatives.

Zero

n = 0

Commonly excluded by definition; this page checks positive numbers only.

Position

Left-to-right count

Do not use right-to-left positions directly without adjusting exponent order.

Armstrong

Different formula

Armstrong uses fixed exponent equal to digit count for all digits.

One digit

1–9

Always Disarium because d1 = d.

Two digits

Only 89 in 10–99

A quick check when listing up to 100.

Large range

Power growth

Use caching or careful bounds if scanning very large intervals.

⚖️ Facts Worth Knowing

Handy follow-ups interviewers sometimes ask.

  • Formal sum. For k-digit n with digits d1…dk, Disarium means n = Σ dii.
  • Single digits. Every n in 1…9 is Disarium.
  • Classics. 89 and 135 are the standard multi-digit examples.
  • Rarity. Disarium numbers become scarce as digit counts grow.

🎯 Practice Problems

Try these variations to lock in the pattern.

1. Verify classics

  • 89, 135, 7 → yes
  • 10, 100 → no

2. Match both styles

  • Right peel vs left-to-right
  • Assert identical booleans

3. Range 1 to 200

  • List all Disarium numbers
  • Expect 1…9, 89, 135

4. Show the breakdown

  • Print each digit^pos term
  • Then the total sum

Notes

  • Rule: digit powers depend on left position.
  • Code: peel from right, decrease exponent each step — or enumerate left-to-right.
  • Remember: Disarium is different from Armstrong.
  • Basic single check is about O(d²); caching can improve range scans.

Quick Takeaway: sum each digit raised to its left-to-right position; if that equals n, it is Disarium.

⏱️ Time and Space Complexity

OperationTimeExtra space
Single check (basic)O(d²)O(1)
Single check (cached powers)O(d)O(d)
Range [1..N]About O(N · d²)O(1)
Wrap Up

🎉 Conclusion

A Disarium number equals the sum of its digits raised to left-to-right position powers. Peel from the right with a descending exponent, or enumerate digits from the left — then compare the sum to n.

Practice the three examples above, then continue to even numbers for a simpler divisibility warm-up.

Always save the original n, start left positions at 1, and distinguish Disarium from Armstrong.

💡 Best Practices

✅ Do

  • State left-position powers first
  • Save original before peeling
  • Test 89, 135, and 10
  • Mention Armstrong difference
  • Restrict to positive n unless asked

❌ Don’t

  • Use Armstrong’s fixed exponent
  • Start positions at 0
  • Forget descending exponents on right peel
  • Compare against a mutated n
  • Treat 0 as Disarium by default

Key Takeaways

Knowledge Unlocked

Five things to remember about Disarium numbers

Check positional digit powers the interview-friendly way.

5
Core concepts
1 02

Index

Left starts at 1

Math
k 03

Peel

Right starts at k

Code
A 04

Contrast

Not Armstrong

Guard
O 05

Complexity

~O(d²)

Analysis

❓ Frequently Asked Questions

A positive integer n is Disarium if the sum of its digits, each raised to the power of its left-to-right position (starting at 1), equals n.
Using % 10 and // 10 is simple. To keep powers correct, we start exponent from total digit count and decrease it each step.
Yes. Python integer arithmetic is exact for big integers, so ** is safe for this kind of interview program.
Most common definitions focus on positive numbers. In this page we check positive integers only.
Yes for 1 to 9, because d^1 = d.
For d digits, checking one number is O(d^2) in the straightforward version with repeated powers, and can be improved with caching.
Armstrong raises every digit to the same power (digit count). Disarium raises each digit to its left-to-right position index.
89 and 135 are classic. In 1 to 100 you also get all of 1 through 9.

Did you Know? 🔊

Besides 89, 135 is a classic Disarium number because 11 + 32 + 53 = 135. Every one-digit positive number 1 to 9 is Disarium.

Continue to Even Number

Learn how to check whether an integer is even using modulo and bit tricks.

Even number tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

9 people found this page helpful