Skip to content

Instantly share code, notes, and snippets.

@bhenry
Created November 24, 2010 16:43
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 bhenry/713956 to your computer and use it in GitHub Desktop.
Save bhenry/713956 to your computer and use it in GitHub Desktop.
;; for 18 and 67 in project euler
(defn max-path-sum
"give it a vector of vectors that form a triangle"
([t] (max-path-sum t (- (count t) 2) (t (dec (count t)))))
([t top bot]
(if (> top 0)
(max-path-sum
t
(dec top)
(vec
(let [row (t top)]
(for [i (range top)]
(+ (row i) (max (bot i) (bot (inc i))))))))
(+ (bot 0) ((t top) 0)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment