Just to get the party started, and without putting much effort into it, you can change this:

next if ! grep { $_<val> == 5 } @combo;

to:

next if none(@a) == 5;

Update: another quick note. Your iterator should be able to be nicely implemented in terms of gather/take. Pugs doesn't have it yet, so I haven't had a chance to play with it enough to be very comfortable, but it would be nice if someone could show how to do that. :-)

Another update: here's my crack at gatherifying your combo generator. I dunno if it's right, but it fits my understanding of how the construct is supposed to work:

sub combo (Int $by is copy, @list is copy) returns Ref { my @position = 0 .. ($by - 2), $by - 2; my @stop = @list.elems - $by .. @list.end; my $done = undef; gather { until $done { my $cur = @position.end; while ++@position[$cur] > @stop[$cur] { --$cur; @position[$cur]++; next if @position[$cur] > @stop[$cur]; my $new_pos = @position[$cur]; @position[$cur .. @position.end] = $new_pos .. ($new_p +os + $by); last; } $done = 1 if @position[0] == @stop[0]; take [ @list[@position] ]; } } }

As we can see, this was a very straightforward change. My understanding is that this should act lazilly -- possibly as a coroutine -- if used in a lazy context. Instead of returning lists, I have it take array references, because I'm not sure if taking a list would Do The Right Thing. Again, this is just my understanding of the feature. I could have this all wrong.

Update on another update: added until loop around body of gather. I think it's correct this time. :-)


In reply to Re: Perl6 Contest: Test your Skills by revdiablo
in thread Perl6 Contest: Test your Skills by Limbic~Region

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.