Beefy Boxes and Bandwidth Generously Provided by pair Networks RobOMonk
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^2: calculating cribbage points

by Limbic~Region (Chancellor)
on Mar 31, 2006 at 11:53 UTC ( [id://540501]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to Re: calculating cribbage points
in thread calculating cribbage points

ikegami,
Your code:
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;
Can be simplified to:
my ($points, %count); ++$count{$_} for @c; $points += $_ * ($_ - 1) for values %count;
I used this trick and several others in RFC: Cribbage::Hand.

Cheers - L~R

Replies are listed 'Best First'.
Re^3: calculating cribbage points
by ikegami (Patriarch) on Mar 31, 2006 at 14:22 UTC
    I don't know cribbage. I didn't even know we were dealing with cribbage. I didn't count the points, just list the pairs. Your code is not so much a simplification as something different.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://540501]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.