Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Optimizing a double loop

by bart (Canon)
on Jun 03, 2010 at 14:33 UTC ( #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? | Other CB clients
Other Users?
Others romping around the Monastery: (2)
As of 2021-10-17 18:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My first memorable Perl project was:







    Results (72 votes). Check out past polls.

    Notices?