Last active
April 10, 2017 13:34
-
-
Save spirinvladimir/e67748d3cbfb862c376f2f661aea7a39 to your computer and use it in GitHub Desktop.
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
(defn doubleBooked [events] | |
(let [sortedEvents (sort-by :start events) | |
toAdd true | |
notToAdd false] | |
(loop [head (first sortedEvents) | |
isAdd notToAdd | |
events (rest sortedEvents) | |
intersect []] | |
(let [neck (first events) | |
tail (rest events)] | |
(if (nil? neck) | |
(if (= toAdd isAdd) | |
(conj intersect head) | |
intersect) | |
(let [headEnd (head :end) | |
neckEnd (neck :end)] | |
(if (> (neck :start) headEnd) | |
(if (= toAdd isAdd) | |
(recur neck notToAdd tail (conj intersect head)) | |
(recur neck notToAdd tail intersect)) | |
(if (> headEnd neckEnd) | |
(recur head toAdd tail (conj intersect neck)) | |
(recur neck toAdd tail (conj intersect head)))))))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ого, это какой язык? похоже на Lisp, но вроде не он)