Last active
April 22, 2017 00:24
-
-
Save hxegon/c04e9426db2d504cc6bf91fd3ce1d4f8 to your computer and use it in GitHub Desktop.
From a list of integers, get the longest increasing subset. This would solve 4clojure problem 53 if 4clojure didn't use clojure 1.4. dedupe is from 1.7 on
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
(fn [coll] | |
(let [parduction-by (fn [predf coll] (->> (partition 2 1 coll) (partition-by predf) (filter #(some predf %)) (map #(mapcat identity %)) (map dedupe))) | |
inc? (fn [[a b]] (= (inc a) b))] | |
(->> (parduction-by inc? coll) (sort-by count) last))) | |
;; for an example of what parduction-by does, it's basically a combination of partition-by, reduce and filter | |
;; I'd like to take out the filter aspect and leave that for the user. | |
(parduction-by inc? '(1 0 1 2 3 0 4 5)) ;; => '((0 1 2 3) (4 5)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment