Created
November 30, 2013 04:02
-
-
Save beppu/7715205 to your computer and use it in GitHub Desktop.
4clojure problem #53
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
; 2013-11-29 SOLVED | |
(defn p53-longest-increasing-sub-seq [s] | |
(let [begin-sequences | |
(fn [s] (rest (reductions (fn [a b] (conj a b)) [] s))) | |
end-sequences | |
(fn [s] (reverse (reduce (fn [mem a] (conj (map (fn [b] (flatten [b a])) mem) (list a))) [] s))) | |
longest | |
(fn [s] (reduce (fn [longest x] (if (> (count x) (count longest)) x longest)) [] s))] | |
(->> (apply concat (map begin-sequences (end-sequences s))) | |
(filter (fn [s] (apply < s))) | |
(filter (fn [s] (> (count s) 2))) | |
(longest) | |
))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment