Created
December 8, 2011 06:54
-
-
Save anonymous/1446327 to your computer and use it in GitHub Desktop.
This file contains 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
;; 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