Skip to content

Instantly share code, notes, and snippets.

@simlun

simlun/gist:4405824

Created Dec 29, 2012
Embed
What would you like to do?
!cleancode Clojure solution to Project Euler problem number 74
(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