Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

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]]"; } } }

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://797141]
[LanX]: met a Canadian yesterday, he suggested building a wall and let the US pay for it
[choroba]: No, but lots of pictures of the Agent Orange victims, plus some deformed foeti
[LanX]: ugh
[choroba]: also, seeing communist propaganda I remember from my childhood... very strange experience

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (4)
As of 2017-02-26 04:43 GMT
Find Nodes?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?

    Results (371 votes). Check out past polls.