gpt-3.5-turbo-0613· OpenAI
WildChat-4.8M (AI2)
A number is said to be Disarium if the sum of its digits raised to their respective…
- User
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(544) ➞ false
isDisarium(518) ➞ true
isDisarium(8) ➞ true
isDisarium(466) ➞ false Notes Position of the digit is 1-indexed. A recursive version of this challenge can be found via this link. solve in javascript
- Assistant
function isDisarium(num) { const numArray = Array.from(String(num), Number); let sum = 0; for (let i = 0; i < numArray.length; i++) { sum += Math.pow(numArray[i], i + 1); } return sum === num; }
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.