in reply to Re: Overlapping portions of sub strings
in thread Overlapping portions of sub strings
But it is also buggy for contained intervals. The input my @range4 = ([0, 20], [5, 8]); will give the output interval ([0, 8]). Here is the complete correct code:
for (my $i = 0; $i < @range; $i++) { my $e = $range[$i][1]; for(my $j = $i+1; $j < @range; $j++) { unless($range[$j][0] > $e) { if ($range[$j][1] > $e) { $e = $range[$i][1] = $range[$j][1]; } splice @range, $j, 1; redo if $j < @range; } } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: Overlapping portions of sub strings
by bart (Canon) on Jan 15, 2003 at 21:54 UTC |