Last active
September 25, 2020 05:18
-
-
Save eduardofcgo/0457b47f14a6fd39f3d27ae46f808622 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn armstrong? [n] | |
(let [n-chars (apply vector (str n))] | |
(= n | |
(int | |
(reduce + | |
(map | |
(comp | |
#(Math/pow % (count n-chars)) | |
#(Character/getNumericValue %)) | |
n-chars)))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function isArmstrong(number) { | |
const numberDigits = Array.from(number.toString()).map(parseInt) | |
const sumPowers = numberDigits | |
.map(digit => Math.pow(digit, numberDigits.length)) | |
.reduce((a, b) => a + b, 0) | |
return sumPowers === number | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def is_armstrong(number): | |
number_str = str(number) | |
return sum(int(char)**len(number_str) for char in number_str) == number |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def isArmstrong(number: Int) = { | |
val numberDigits = number.toString.map(Character.getNumericValue) | |
number == numberDigits.map(Math.pow(_, numberDigits.length)).sum | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment