Find the Intersection of 2 Sets in Unioned Interval Notation
Given two sets of real numbers described as the union of intervals, output a description of the intersection of these two sets as a union of the same type of interval.
The input sets will always consist of unions of intervals such that each interval begins and ends at a different integer (i.e. no interval has measure zero). However, different intervals in the same set may begin or end at the same integer or overlap.
The output set must also be a union of intervals which begin and end at integers, but no interval in the output may overlap any other even at a single integer.
The input may take any form that is suitable for your language of choice, as long as it consists of two lists of pairs of integers.
For example, you may represent the set as:
[-10,-4]u[1,5]u[19,20]
Or as:
[[-10,-4],[1,5],[19,20]]
Or as:
[-10,-4;1,5;19,20]
Your output representation must be identical to your input representation (except that it is only one list of intervals instead of two).
Examples/Test cases:
Input:
[[[-90,-4],[4,90]],[[-50,50]]]
Output:
[[-50,-4],[4,50]]
In other words, we're intersecting the set that contains all real numbers between -90 and -4 and all real numbers between 4 and 90 with the set that contains all real numbers between -50 and 50. The intersection is the set containing all real numbers between -50 and -4 and all real numbers between 4 and 50. A more visual explanation:
-90~~~~~-4 4~~~~~90 intersected with
-50~~~~~~~~50 yields:
-50~-4 4~~50
Input:
"[-2,0]u[2,4]u[6,8]
[-1,1]u[3,5]u[5,9]"
Output:
"[-1,0]u[3,4]u[6,8]"
Input:
[-9,-8;-8,0;-7,-6;-5,-4]
[-7,-5;-1,0;-8,-1]
Output:
[-8,0]
Invalid Output (even though it represents the same set):
[-8,0;-7,-5;-5,0]
Scoring:
This is code-golf so shortest source in bytes wins, as potentially modified by the following bonus.
Bonus:
-15% if you also support positive and negative infinity as bounds of intervals. You may choose what token(s) represent these numbers. (And yes, infinity is a number in the hyperreals ;P)
[[[4,90],[-90,-4]],[[-50,50]]]
\$\endgroup\$