Skip to content

Instantly share code, notes, and snippets.

Created October 29, 2009 04:14
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/221142 to your computer and use it in GitHub Desktop.
Save anonymous/221142 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 has-89? [chain]
(let [f (first chain)]
(if (= 89 f)
true
(if (= 1 f)
false
(recur (rest chain))))))
; took 18 minutes, answer: 8581146
(println (count (filter #(has-89? (chain %)) (range 1 10000000))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment