Skip to content

Instantly share code, notes, and snippets.

Created December 8, 2011 06:54
Show Gist options
  • Save anonymous/1446327 to your computer and use it in GitHub Desktop.
Save anonymous/1446327 to your computer and use it in GitHub Desktop.
;; flengyel's solution to Longest Increasing Sub-Seq
;; https://4clojure.com/problem/53
(fn [v]
(let [[maybe n cur _]
(let [v1 (first v)]
(reduce
(fn
[[longest maxlen current prv] elt]
(if (>= prv elt)
(if (> (count current) maxlen)
[current (count current) [elt] elt]
[longest maxlen [elt] elt])
[longest maxlen (conj current elt) elt]))
[[v1] 1 [v1] v1]
(rest v)))]
(cond (< n (count cur)) cur (= 1 n)[]
:else maybe
)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment