Skip to content

Instantly share code, notes, and snippets.

@simlun
Created December 29, 2012 09:57
Show Gist options
  • Select an option

  • Save simlun/4405824 to your computer and use it in GitHub Desktop.

Select an option

Save simlun/4405824 to your computer and use it in GitHub Desktop.

Revisions

  1. simlun created this gist Dec 29, 2012.
    8 changes: 8 additions & 0 deletions gistfile1.clj
    Original 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)