+ 1

Challenge:

Make a program using an array, that finds all numbers from 0 to 99999999 (all numbers until 8 digit numbers) that the the sum of their separate digits raised to the N power that the user provides gives the initial number. For ex. if N=4 the number 1634 is a correct answer, since 1^4+6^4+3^4+4^4=1634

20th Nov 2017, 3:25 PM
Manos Strb
Manos Strb - avatar
2 Answers
+ 8
ES6: for (var num = 1; num < Math.pow(10, 8); num++) { var str = num.toString().split(""); if (str.reduce(function(a, b) { return a + Math.pow(b, str.length); }, 0) === num) document.write(num + "<br>"); }
20th Nov 2017, 5:09 PM
Krishna Teja Yeluripati
Krishna Teja Yeluripati - avatar
21st Nov 2017, 4:55 AM
sayan chandra
sayan chandra - avatar