Created
February 19, 2012 21:46
-
-
Save mattdeboard/1866001 to your computer and use it in GitHub Desktop.
4clojure #53
This file contains hidden or 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
| ;; Breaks on [2 3 3 4 5] | |
| ;; http://www.4clojure.com/problem/53#prob-title | |
| (defn subseq- [coll] | |
| (partition-by (fn [x] (= 1 (- (second x) (first x)))) | |
| (filter #(< (first %) (second %)) | |
| (partition 2 1 coll)))) | |
| ;; Example | |
| (def test-vecs [[1 0 1 2 3 0 4 5] [5 6 1 3 2 7] [2 3 3 4 5] [7 6 5 4]]) | |
| (vector | |
| (for [i test-vecs] | |
| (vec (set (flatten (first (subseq- i))))))) | |
| ;; Result: [([0 1 2 3] [5 6] [2 3 4 5] [])] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
yea, I tried to use partition-by, but everything that I have tried breaks on [2 3 3 4 5].