range consolidation (from Rosetta Code)
We can represent a range of numbers as a tuple, like this [1 4]
. That means all real numbers between 1 and 4, including 1 and 4. The task is to write a function that takes a collection of ranges and consolidates them so that there are no overlapping ranges.
For example, [1 4]
and [3 5]
overlap, so they would be consolidated to [1 5]
. [10.2 15]
does not overlap, so it doesn't change.
(consolidate [[1 4] [3 5] [10.2 15]]) ;=> [[1 5] [10.2 15]]
There can be any number of ranges in that collection, and they could be in any order.