Created
February 1, 2017 15:29
-
-
Save craftybones/323d25b5038e7df654b0201973ac6d29 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn max-adjacents [coll] | |
(map max coll (rest coll))) | |
(defn sum-of [prev current] | |
(map + current (max-adjacents prev))) | |
(defn max-path-sum [tree] | |
(first (reduce sum-of (reverse tree)))) | |
;; To test use the following | |
;; (def tree [[3] | |
;; [7 4] | |
;; [2 4 6] | |
;; [8 5 9 3]] | |
;; (max-path-sum tree) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment