Skip to content

Instantly share code, notes, and snippets.

@beppu
Created November 30, 2013 04:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save beppu/7715205 to your computer and use it in GitHub Desktop.
Save beppu/7715205 to your computer and use it in GitHub Desktop.
4clojure problem #53
; 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