Perl - determining the intersection of several numeric ranges -
i able load long list of positive integer ranges , create new "summary" range list union of intersections of each pairs of ranges. and, want in perl. example:
sample ranges: (1..30) (45..90) (15..34) (92..100) intersection of ranges: (15..30)
the way think of using bunch of nested if
statements determine starting point of sample a, sample b, sample c, etc. , figure out overlap way, it's not possible hundreds of sample, each containing numerous ranges.
any suggestions appreciated!
the first thing should when need thing take @ cpan see tools available of if has solved problem already.
set::intspan , set::intrange on first page of results "set" on cpan.
what want union of intersection of each pair of ranges, algorithm follows:
- create empty result set.
- create set each range.
- for each set in list,
- for each later set in list,
- find intersection of 2 sets.
- find union of result set , intersection. new result set.
- for each later set in list,
- enumerate elements of result set.
Comments
Post a Comment