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

Re: Optimizing a double loop

by bart (Canon)
on Jun 03, 2010 at 14:33 UTC ( [id://842931]=note: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    %step = ( 20 => 1, 50+1 => -1 );
    
  2. or download this
    my %step;
    foreach(@range) {
        $step{ $_->[0] }++;
        $step{ $_->[1]+1 }--;
    }
    
  3. or download this
    my @edge = sort { $a <=> $b } keys %step;
    my $step = 0;
    ...
        }
        $arr[$i] += $step;
    }
    
  4. or download this
    @arr = (0) x 120;
    @range = ([20, 50], [30, 100]);
    
  5. or download this
    0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 
    +2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
    + 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 
    +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
    

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (4)
As of 2024-03-29 13:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found