P is for Practical | |
PerlMonks |
Re: calculating cribbage pointsby jdporter (Paladin) |
on Mar 30, 2006 at 22:46 UTC ( [id://540306]=note: print w/replies, xml ) | Need Help?? |
Well, other people have talked about how to do loops, or use modules to assist in the problem. I'm going to take an approach which is more customized to the specific application. Even so, it wouldn't be hard to extend if, for example, you started playing 7-card cribbage. :-)
The key is the @combos array. It contains a set of "combination keys", such as for all the valid subsets of cards in a hand. It turns out there's only 26 of them. (It does not include any keys of length 1, since there's no way to get 15 from a single card.) We rely on grep returning the number of matches — that's the number of fifteens found.
We're building the house of the future together.
In Section
Seekers of Perl Wisdom
|
|