sub score ( @hand ) returns Int { my Int $score = 0; my %cardvals; %cardvals{ @hand[0..4]<num> }++; # [234] of a kind $score += [*]($_,$_-1) for %cardvals.values; # Flushes $score += 4 if @hand[0]<suit> ~~ all( @hand[1..3]<suit> ); $score++ if @hand[4]<suit> ~~ all( @hand[0..3]<suit> ); # Fifteens if any( @hand<val> ) ~~ 5 && any( @hand<val> ) ~~ 10 { $score += 2 * ( grep -> $_<val> ~~ 5, @hand ) * ( grep -> $_<val> ~~ 10, @hand ); } # Runs SPAN: for 5 .. 3 -> $span { for 1 .. 11 -> $start { if all( @cardvals{ $start .. $start + $span } ) { $score += $span; last SPAN; } } } # Right-Jack $score++ if grep -> $_<disp> ~~ 'J' && $_<suit> ~~ @hand[4]<suit>, @hand[0..3]; return $score; }
In reply to Re: Perl6 Contest: Test your Skills
by dragonchild
in thread Perl6 Contest: Test your Skills
by Limbic~Region
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |