Created
October 29, 2009 04:14
-
-
Save anonymous/221142 to your computer and use it in GitHub Desktop.
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
; 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