http://www.perlmonks.org?node_id=927680


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

I like that because it only does one comparison per row.

I considered a join approach too, but had two concerns. First, while it works in the specific case, if the NxN matrix held more complex strings, it could fail, so I saw it as not general enough to a broader application of the problem. Nevertheless, the problem itself is specific, and your version works great.

The other concern is that it lacks the optimization of failing as soon as the first non-zero entry is found on a given row. By joining the row, we're already implicitly touching the entire row. On the other hand, it does have the merit of only doing one comparison per row, which is nice. The shortcoming is that it has to join the entire row even if the first element of the row would result in a rejected row.

Fun!


Dave

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