Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: An exploration of higher-level-language approaches to the "First all-zero row in an NxN matrix" problem (goto Considered Harmful)

by GrandFather (Cardinal)
on Sep 24, 2011 at 21:45 UTC ( #927686=note: print w/ replies, xml ) Need Help??


in reply to An exploration of higher-level-language approaches to the "First all-zero row in an NxN matrix" problem (goto Considered Harmful)

In Perl we frown on the old C style for loop because almost always there is a better way to do it with a Perl foreach style loop. However, not always. The iterator variant below uses a C style loop to remember the last column and last row dealt with to allow a simple last to short circuit the loops with the state of the loop counter propagating the success or failure.

my $i; for ($i = 0; $i < @array; ++$i) { my $row = $array[$i]; my $j; for ($j = 0; $j < @$row; ++$j) { last if $row->[$j]; } last if $j == @$row; } print "All zero row at $i\n" if $i != @array;

Given CountZero's test matrix prints:

All zero row at 3
True laziness is hard work


Comment on Re: An exploration of higher-level-language approaches to the "First all-zero row in an NxN matrix" problem (goto Considered Harmful)
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (10)
As of 2014-09-01 14:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (13 votes), past polls