Created
June 18, 2011 10:47
-
-
Save hyone/1032985 to your computer and use it in GitHub Desktop.
4clojure #53 - Longest continuous increasing subsequence
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
;; hyone's solution to Longest Increasing Sub-Seq | |
;; https://4clojure.com/problem/53 | |
(fn longest-inc-seq [coll] | |
(reduce #(let [len-a (count %1) | |
len-b (count %2)] | |
(if (and (> len-b 1) (> len-b len-a)) %2 %1)) | |
[] | |
(reductions | |
(fn [xs y] | |
(if (> y (last xs)) (conj xs y) [y])) | |
[(first coll)] | |
(rest coll)))) |
(fn [coll]
(let [a (partition-by #(apply < %) (partition 2 1 coll))
b (filter (fn [[[x1 x2]]] (< x1 x2)) a)
c (first (sort-by count > b))]
(concat (first c) (map last (rest c)))))
lonest of mine . :
(fn [coll]
(let [group-coll-index (fn [coll] (partition-by #(take-last 1 %)
(partition 2
(interleave coll
(flatten
(partition-by identity
(map + coll (iterate dec 0)))
)))))
]
(if (>= (apply max (map count (group-coll-index coll))) 2)
(flatten (map butlast (last (sort-by count (group-coll-index coll)))))
[])
)
)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Cool! Here is mine.