Skip to content

Instantly share code, notes, and snippets.

Created October 29, 2009 03:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/221079 to your computer and use it in GitHub Desktop.
Save anonymous/221079 to your computer and use it in GitHub Desktop.
; Project Euler, problem 92
(use 'clojure.contrib.math)
(defn digits-of [n]
(map read-string (map str (str n))))
(defn chain [n]
(let [sum (apply + (map #(expt % 2) (digits-of n)))]
(lazy-seq
(cons n (chain sum)))))
(defn is-in? [xs n]
(some #(= % n) xs))
(println (count (filter #(is-in? (chain %) 89) (range 1 10000000)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment