Skip to content

Instantly share code, notes, and snippets.

@ypsilon-takai
Last active September 28, 2015 06:38
Show Gist options
  • Select an option

  • Save ypsilon-takai/1400109 to your computer and use it in GitHub Desktop.

Select an option

Save ypsilon-takai/1400109 to your computer and use it in GitHub Desktop.
project euler 67
;; reviced for clojure 1.4
;; Problem 67 : 2011/11/28
;; "Elapsed time: 52.128413 msecs"
(defn pe-67 [input-list]
(apply max
(reduce (fn [root new]
(let [rt-r (cons 0 root)
rt-l (conj root 0)]
(mapv #(+ %1 (max %2 %3))
new rt-l rt-r)))
input-list)))
;; Support func to read data from the file.
(require '[clojure.java.io :as io])
(defn pe-67-with-file [input-file]
(with-open [in-file (io/reader input-file)]
(pe-67
(mapv (fn [line-dat]
(mapv (fn [s] (Integer. s))
(.split line-dat " ")))
(line-seq in-file)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment