Skip to content

Instantly share code, notes, and snippets.

@Crowbrammer
Last active April 22, 2022 16:51
Show Gist options
  • Save Crowbrammer/fb3c171ffdfa0224827a95c68ab1e0ee to your computer and use it in GitHub Desktop.
Save Crowbrammer/fb3c171ffdfa0224827a95c68ab1e0ee to your computer and use it in GitHub Desktop.
Sum of Intervals Solution
(defn sum-intervals
"c describes parts of a sequence. Some parts overlap.
Give a sum of all the unique items in the sequence."
[c]
;; Build the items
;; Pour 'em all into a single collection
;; (Implementation: Is range inclusive or exclusive? Doesn't matter. If i)
;; Set 'em
;; Count 'em.
(->> (map #(range %1 %2) c)
(apply concat)
(set)
(count)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment