in reply to Re: calculating cribbage points
in thread calculating cribbage points
Can be simplified to:my %count; ++$count{$_} foreach @c; my @pairs = grep { $count{$_} >= 2 } sort { $b <=> $a } @c; my @kind3 = grep { $count{$_} >= 3 } @pairs; my @kind4 = grep { $count{$_} >= 4 } @kind3;
I used this trick and several others in RFC: Cribbage::Hand.my ($points, %count); ++$count{$_} for @c; $points += $_ * ($_ - 1) for values %count;
Cheers - L~R
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: calculating cribbage points
by ikegami (Patriarch) on Mar 31, 2006 at 19:22 UTC |