← Back to challenges

Recursion: Disarium Number

JavaScriptHardrecursionnumbersmathvalidation

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

isDisarium(75) ➞ false
// 7^1 + 5^2 = 7 + 25 = 32

isDisarium(135) ➞ true
// 1^1 + 3^2 + 5^3 = 1 + 9 + 125 = 135

isDisarium(518) ➞ false

isDisarium(518) ➞ true

isDisarium(544) ➞ false

isDisarium(8) ➞ true

isDisarium(466) ➞ false

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.
  • A collection of challenges in recursion can be found via this link.
javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.