Skip to content

Instantly share code, notes, and snippets.

@malloc47 malloc47/sequence.clj
Last active Jun 28, 2016

What would you like to do?
(defn happy-next
(let [digits (->> n str seq (map #(Character/digit % 10)))]
(->> (map * digits digits)
(apply +))))
(defn happy'
[n seen]
(loop [n n seen seen]
(= 1 n) true
(contains? seen n) false
:else (recur (happy-next n) (conj seen n)))))
(defn happy?
(happy' n #{}))
(defn happy*
(cons n (lazy-seq (happy* (happy-next n)))))
(defn happy?
(->> (happy* n)
(reductions conj [])
(take-while #(= (distinct %) %))
(= 1)))
(def happy-seq
(->> (range)
(map inc)
(filter happy?)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.