Skip to content

Instantly share code, notes, and snippets.

@spirinvladimir
Last active April 10, 2017 13:34
Show Gist options
  • Save spirinvladimir/e67748d3cbfb862c376f2f661aea7a39 to your computer and use it in GitHub Desktop.
Save spirinvladimir/e67748d3cbfb862c376f2f661aea7a39 to your computer and use it in GitHub Desktop.
(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))))))))))
@FireAlkazar
Copy link

Ого, это какой язык? похоже на Lisp, но вроде не он)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment