Came over a similar problem in a project I'm working on and found it quite hard to solve it without excesive use of
if. I'm eager to see if anyone can come up with more elegant solutions to this, with the aribitary numbers I have given to the line segments.
You are given two integers that act like the end points of a line segment. Determine what existing line segments this line will overlap with.
Intervals / line segments
The other lines, named Q, W, E, R and T, are as following:
Q: 0 - 7 W: 8 - 18 E: 19 - 32 R: 33 - 135 T: 136 -
The last one, T, starts at 136 and has no end point.
Given the numbers
27, the line will overlapp with
E. This can be roughly illustrated like this:
Q W E R T ---+--+---+-------+-----------+----- 0 7 18 32 135 +---------+ 5 27 (somewhat arbitrary scale)
Two integers from stdin.
A String containing the names of the lines that our new line overlap with, for instance in the example above