Created
November 17, 2016 15:18
-
-
Save benkamphaus/f933d23aea0e5c2b4674ab8e111887c6 to your computer and use it in GitHub Desktop.
Find narcissistic numbers in Clojure (non-optimized)
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 narcissistic? | |
"Returns true if n with m digits is equal to each digit in n to the | |
m exponent." | |
[n] | |
(let [digits (map #(Character/digit % 10) (str n)) | |
n-digits (count digits) | |
exps (map #(Math/pow % n-digits) digits)] | |
(== n (apply + exps)))) | |
(take 10 (filter narcissistic? (iterate inc 10))) | |
;; (153 370 371 407 1634 8208 9474 54748 92727 93084) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment