Created
October 15, 2012 10:44
-
-
Save Centaur/3891910 to your computer and use it in GitHub Desktop.
max sub seq clojure version
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 get-max-sub [h & t] | |
(let [max-sub (fn [[head & tail] found next] | |
(if head | |
(if (> head (last next)) | |
(let [next2 (conj next head)] | |
(if (= (count next) (count found)) | |
(recur tail next2 next2) | |
(recur tail found next2) | |
) | |
) | |
(recur tail next, [head])) | |
(if (= 1 (count found)) [] found) | |
))] | |
(max-sub t [h] [h])) | |
) | |
(println (get-max-sub 1 0 1 2 3 0 4 5)) | |
(println (get-max-sub 1 5 6 2 3)) | |
(println (get-max-sub 8 7 6 5)) | |
(println (get-max-sub 1 2)) | |
(println (get-max-sub 2 1)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment