Skip to content

Instantly share code, notes, and snippets.

@Centaur
Created October 15, 2012 10:44
Show Gist options
  • Save Centaur/3891910 to your computer and use it in GitHub Desktop.
Save Centaur/3891910 to your computer and use it in GitHub Desktop.
max sub seq clojure version
(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