Created
November 12, 2013 03:08
-
-
Save Ariarule/7424829 to your computer and use it in GitHub Desktop.
;; ariarule's solution to Intervals
;; https://4clojure.com/problem/171
;; Slightly bleh
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 [s] | |
(vec (apply sorted-set (map vec (let [t (set (sort s)) | |
w (rest (butlast t)) | |
v (sort (if (empty? t) t (cons (first t) (conj (vec (map first | |
(remove | |
#(and (contains? (second %) 1) (contains? (second %) -1)) | |
(reduce #(assoc %1 %2 (set (map (partial - %2) t))) {} w)))) (last t)))))] | |
(if (empty? v) | |
v | |
(partition 2 (reverse (reduce | |
#(if (or (t (dec %2)) (t (inc %2))) | |
(cons %2 %1) | |
(cons %2 (cons %2 %1))) | |
[] | |
v))))))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment