How to add up multiple intervals and check if they complete a known interval?

136 Views Asked by At

If my initial/known interval is [0,20) or length 19

And the 3 intervals are: [0,5), [5,10), [10,20)

Using the standard interval addition formula:

[a,b]+[c,d] = [a+c,b+d] I get the result [15,35) [1] not [0,20)

How do I multiply them to check if they add up to the known interval?

Also, there are cases where the 3 intervals don't add up: [0,5), [5,10), [15,20) - in this case, the complete puzzle is missing interval [10,15), so how do I check for that?

1

There are 1 best solutions below

1
On

I understand you mean intervals of integers, e.g., $[0,5)=\{0,1,2,3,4\}$ (range in Python). To check whether given intervals $[a_i,b_i)$, $i=1,\dots,n$, form a partition of $[A,B)$, you can do the following:

  1. Sort the intervals in order of increasing $a_i$.
  2. Check that $a_1=A$, $b_1=a_2$, $b_2=a_3$, ..., $b_n=B$. If all of these hold, you have a partition. Otherwise not.