<p>What is the best way to find out whether two number ranges intersect?</p>

<p>My number range is <strong>3023-7430</strong>, now I want to test which of the following number ranges intersect with it: &lt;3000, 3000-6000, 6000-8000, 8000-10000, >10000. The answer should be <strong>3000-6000</strong> and <strong>6000-8000</strong>.</p>

<p>What's the nice, efficient mathematical way to do this in any programming language?</p>

Just a pseudo code guess:
```
```
Set<Range> determineIntersectedRanges(Range range, Set<Range> setofRangesToTest)
{
  Set<Range> results;
  foreach (rangeToTest in setofRangesToTest)
  do
    if (rangeToTest.end <range.start) continue; // skip this one, its below our range
    if (rangeToTest.start >range.end) continue; // skip this one, its above our range
    results.add(rangeToTest);
  done
  return results;
}
```
```