-
-
Save mlb-/8539d36782246f7f03de to your computer and use it in GitHub Desktop.
clojure happy number http://www.4clojure.com/problem/86
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 happy-numbers | |
[n] | |
(letfn [(next-happy [n] | |
(->> n | |
str | |
(map (comp int | |
#(Math/pow % 2) | |
read-string | |
str)) | |
(reduce +)))] | |
(loop [n n | |
prev #{}] | |
(cond | |
(= 1 n) true | |
(prev n) false | |
:else (recur (next-happy n) | |
(conj prev n)))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment