Skip to content

Instantly share code, notes, and snippets.

@simlun
Created December 29, 2012 09:57
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 simlun/4405824 to your computer and use it in GitHub Desktop.
Save simlun/4405824 to your computer and use it in GitHub Desktop.
!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