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:

  1. create empty result set.
  2. create set each range.
  3. for each set in list,
    1. for each later set in list,
      1. find intersection of 2 sets.
      2. find union of result set , intersection. new result set.
  4. enumerate elements of result set.

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -