Created
December 29, 2012 09:57
-
-
Save simlun/4405824 to your computer and use it in GitHub Desktop.
Revisions
-
simlun created this gist
Dec 29, 2012 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,8 @@ (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)