I don't believe @hand[0..4]<num> works. I believe you need the hyper operator for that as in @hand[0..4]>>.<num>. Since the slice represents the entire array it can be dropped all together - @hand>>.<num> I am not sure about the post increment also needing to be distributed either but my hunch is that it should be.my %cardvals; %cardvals{ @hand[0..4]<num> }++
Clever! To explain what is happening from right to left: The values of the hash are the counts of each in the hand. The infix operator gets the product of the count and the count minus 1 so ( 1 => 0, 2 => 2, 3 => 6, 4 => 12 ). The result is then added to the current $score.# [234] of a kind $score += [*]($_,$_-1) for %cardvals.values;
I am fairly certain this is inadequate. Consider 2 + 3 + 6 + 4 = 15. (no fives or tens)# Fifteens if any( @hand<val> ) ~~ 5 && any( @hand<val> ) ~~ 10 { $score += 2 * ( grep -> $_<val> ~~ 5, @hand ) * ( grep -> $_<val> ~~ 10, @hand ); }
Again Clever! In this case though it isn't quite enough. To explain what I believe is going on is that you already have all of the number values stored in a hash. You start looking for runs of 5 then 4 then 3. Then you check for all possible runs of that length by checking if all cards in the hash have a true value. Unfortunately this is where it goes wrong. Consider:# Runs SPAN: for 5 .. 3 -> $span { for 1 .. 11 -> $start { if all( @cardvals{ $start .. $start + $span } ) { $score += $span; last SPAN; } } }
Your approach aborts after the first run is found.Hand = 2,3,3,4 5 2,3,4,5 = 4 points 2,3,4,5 = 4 points = 8 points total
Cheers - L~R
In reply to Re^2: Perl6 Contest: Test your Skills
by Limbic~Region
in thread Perl6 Contest: Test your Skills
by Limbic~Region
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |