My first impulse was to write basically the List::MoreUtils solutions in Perl 6. It has all() and .all built in, but no firstidx, so the solution goes through the detour of creating (index => value) pairs first:

my @array = [ qw/ 1 1 1 1 1 / ], [ qw/ 0 1 1 0 0 / ], [ qw/ 0 0 0 0 1 / ], [ qw/ 0 0 0 0 0 / ], [ qw/ 0 1 0 -1 0 / ], ; say @array.pairs.first({.value.all == 0 }).key;

Now .all == 0 should ring a bell for Perl 6 developers, there's a simplification around the corner:

say @array.pairs.first(*.value.none).key;

A good solution always plays to the strength of the language that it is implemented in. If Perl 6 didn't have junctions, I'd go the route of calculating the sum instead, which is readily available:

say @array.pairs.first({ 0 == [+] .value.list}).key;

(This assumes that no negative entries are allowed. If they are allowed, one could add a >>.abs after the .list to fix it).

Another approach is to use the fact that 0 is the only number that evaluates to False in boolean context:

say @array.pairs.first({ not [||] .value.list}).key;

In both cases I make use of the fact that [op] applies the operator op to a list of values.


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) by moritz
in thread An exploration of higher-level-language approaches to the "First all-zero row in an NxN matrix" problem (goto Considered Harmful) by davido

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.