You're absolutely right on the runs. Rewrite it as such:
Since %cardvals contains the number of each card, that's the number of times the run should be multiplied by. This also correctly handles 2,3,3,4,4. The span is 3 and the multiplier is 1*2*2, which results in 12.# Runs SPAN: for 5 .. 3 -> $span { for 1 .. 11 -> $start { if all( @cardvals{ $start .. $start + $span } ) { $score += $span [*] %cardvals{ $start .. $start + $span}; last SPAN; } } }
Update: I'm a little reduce-happy. That should really be:$score += $span *<< %cardvals{ $start .. $start + $span};
You're also absolutely right on the fifteens. There are probably several ways to solve it. There's the brute-force method you used, which is perfectly adequate. However, I think we can use junctions to solve our problem. (Junctions rock, you know.)
I'm not sure that's legal. I've cross-posted it to P6L for @Larry to rip apart.# Fifteens $score += 2 * all( 15 == [+]@hand{ any( 0 .. 4 ) } };
Update: After japhy's comments, it should probably look something like:
I'm trying to figure out the correct way to handle the combinations as a single item.# Fifteens $score += 2 * all( 15 == [+]%hand{ any( 0 .. 4 ) } )>>.<num>;
In reply to Re^3: Perl6 Contest: Test your Skills
by dragonchild
in thread Perl6 Contest: Test your Skills
by Limbic~Region
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |