Skip to content

Instantly share code, notes, and snippets.

@mlb-
Forked from featheredtoast/happy-numbers.clj
Last active October 8, 2015 23:56
Show Gist options
  • Save mlb-/8539d36782246f7f03de to your computer and use it in GitHub Desktop.
Save mlb-/8539d36782246f7f03de to your computer and use it in GitHub Desktop.
clojure happy number http://www.4clojure.com/problem/86
(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