Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: boolean calculation with very large data

by ccn (Vicar)
on Sep 24, 2009 at 07:26 UTC ( #797141=note: print w/ replies, xml ) Need Help??


in reply to boolean calculation with very large data

#!/usr/bin/perl -l my $region1=[[1,2],[5,7]]; my $region2=[[2,6]]; sub max { return $_[0] > $_[1] ? $_[0] : $_[1]; } sub min { return $_[0] < $_[1] ? $_[0] : $_[1]; } sub getIntersect { my ($reg1, $reg2) = @_; return if $reg1->[1] < $reg2->[0]; return if $reg1->[0] > $reg2->[1]; return (max($reg1->[0], $reg2->[0]), min($reg1->[1], $reg2->[1])); } foreach my $r1 (@$region1) { foreach my $r2 (@$region2) { if( my @is = getIntersect($r1, $r2) ) { print "[$is[0], $is[1]]"; } } }


Comment on Re: boolean calculation with very large data
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://797141]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (9)
As of 2014-11-26 13:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (171 votes), past polls