Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Given two ranges, do the following: 1) check if the start or the end of each range deviate by more than +five 2) check if the intersection of the range is at least half its union
use Set::IntSpan; $range1 = Set::IntSpan->new([45 .. 60]); $range2 = Set::IntSpan->new([49 .. 57]); $intersect_range = $range1->intersect($range2); $union_range = $range1->union($range2); print "INTERSECT:".$intersect_range."\nUNION:".$union_range."\n"; $diff_between_starts = abs($range1->min-$range2->min); $diff_between_ends = abs($range1->max-$range2->max); print "START DIFF:$diff_between_starts\n"; print "END DIFF:$diff_between_ends\n"; if($diff_between_starts<=5 && $diff_between_ends<=5) {print "ALL IS OK +\n";} else {print "PROBLEM\n";}
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: union and intersection of ranges
by syphilis (Archbishop) on Feb 09, 2023 at 00:22 UTC | |
by BillKSmith (Monsignor) on Feb 09, 2023 at 17:07 UTC | |
|
Re: union and intersection of ranges
by LanX (Saint) on Feb 09, 2023 at 00:29 UTC | |
|
Re: union and intersection of ranges
by Marshall (Canon) on Feb 09, 2023 at 08:31 UTC |