You are viewing a single comment's thread. Return to all comments →
Here is a clojure solution passed both #18 and #67.
(defn max-path-sum [tri] (let [max-sum (fn [a b c] (+ a (max b c))) fold-by (fn [bs as] (map max-sum as bs (rest bs)))] (first (reduce-right fold-by tri))))
Fold the triangle from bottom, taking the some of current element and max of adjacent elements below.
Project Euler #67: Maximum path sum II
You are viewing a single comment's thread. Return to all comments →
Here is a clojure solution passed both #18 and #67.
Fold the triangle from bottom, taking the some of current element and max of adjacent elements below.