← Back to challenges

Recursion: Disarium Number

PythonHardrecursionnumbersmathvalidation

Instructions

A number is said to be Disarium if the sum of its digits raised to their respective positions is the number itself. Create a function that determines whether a number is a Disarium or not.

Examples

is_disarium(75) ➞ False
# 7^1 + 5^2 = 7 + 25 = 32

is_disarium(135) ➞ True
# 1^1 + 3^2 + 5^3 = 1 + 9 + 125 = 135

is_disarium(544) ➞ False

is_disarium(518) ➞ True

is_disarium(466) ➞ False

is_disarium(8) ➞ True

Notes

  • Position of the digit is not likely its index.
  • You are expected to solve this challenge via recursion.
  • An iterative version of this challenge can be found via this link.
python3
Loading editor…
⌘ ↡ to run
Walks through the solution with reasoning and edge cases.