Skip to content

Instantly share code, notes, and snippets.

@Ariarule
Created November 12, 2013 03:08
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 Ariarule/7424829 to your computer and use it in GitHub Desktop.
Save Ariarule/7424829 to your computer and use it in GitHub Desktop.
;; ariarule's solution to Intervals ;; https://4clojure.com/problem/171 ;; Slightly bleh
(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