Created
December 29, 2012 09:57
-
-
Save simlun/4405824 to your computer and use it in GitHub Desktop.
!cleancode Clojure solution to Project Euler problem number 74
This file contains hidden or 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
(defn euler074 [up-to chain-len] (let [right-chain-len? #(= chain-len (count %)) | |
start-nrs (range 1 (inc up-to))] (count (filter right-chain-len? (map (fn | |
[start-nr] (loop [chain #{start-nr} prev-trm start-nr] (let [next-trm (reduce + | |
(map (memoize (fn [n] (if (= n 0) 1 (reduce * (range 1 (inc n)))))) (map #(- | |
(int %) (int \0)) (str prev-trm))))] (if (contains? chain next-trm) chain (recur | |
(conj chain next-trm) next-trm))))) start-nrs))))) | |
(euler074 1000000 60) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment