Skip to content

Instantly share code, notes, and snippets.

@dbyrne
Created June 8, 2010 14:14
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 dbyrne/430074 to your computer and use it in GitHub Desktop.
Save dbyrne/430074 to your computer and use it in GitHub Desktop.
Project Euler #18 & #67 - Clojure
(with-test
(defn maximal-path [tree-file]
(with-open [rdr (BufferedReader. (FileReader. tree-file))]
(let [lines (reverse
(map
(fn [x]
(map #(Integer. %) (re-seq #"\d+" x)))
(line-seq rdr)))]
(first
(reduce
(fn [a b]
(map max (map + b a) (map + b (rest a))))
lines)))))
(is (= (maximal-path "prob_18.txt") 1074))
(is (= (maximal-path "prob_67.txt") 7273)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment