### Re: Generating all 5-card hands

by merlyn (Sage)
 on May 18, 2005 at 14:57 UTC ( #458236=note: print w/ replies, xml ) Need Help??

in reply to Generating all 5-card hands

You might look at Games::Cards for reusable code regarding scoring and representing hands.

For generating all combinations of 52 cards taken 5 at a time, search here for combinations. I'm sure we've covered this quite a bit. {grin}

But are you really ready to process all 2598960 iterations? At 100 per second, that's still about a third of a day. Maybe you should use some rules instead.

-- Randal L. Schwartz, Perl hacker
Be sure to read my standard disclaimer if this is a reply.

Comment on Re: Generating all 5-card hands
Replies are listed 'Best First'.
Re^2: Generating all 5-card hands
by thor (Priest) on May 18, 2005 at 15:58 UTC
But are you really ready to process all 2598960 iterations?
Nope. The number that you mention is 52-choose-5: the number of 5-card hands possible sans restrictions. I consider only those hands that have at least one 5 in them to be interesting. This takes out a significant portion (by my math, it leaves only 886656). I will further reduce the set by using the fact that a cribbage hand is inherently non-ordered and, for my purposes, suit doesn't matter. So, I'll not bother scoring a hand if I've already seen a hand with the same cards in it. I just did it in 30 seconds, generating 1820 distinct hands. :)

thor

Feel the white light, the light within
Be your own disciple, fan the sparks of will
For all of us waiting, your kingdom will come

My point is that for the purposes of this exercise, the suit doesn't matter. So, at some point, you'll end up choosing an equivalent hand to one that has already been done. For each combination of ranks, there are a fair number of equivalent hands that differ only in the suits of the individual cards. For this exercise, those hands are equivalent, so there's no point in scoring the second hand if the first hand has already been dealt with. Perhaps I mis-spoke before.

thor

Feel the white light, the light within
Be your own disciple, fan the sparks of will
For all of us waiting, your kingdom will come

Re^2: Generating all 5-card hands
by Limbic~Region (Chancellor) on Mar 31, 2006 at 20:30 UTC
merlyn,
For generating all combinations of 52 cards taken 5 at a time....But are you really ready to process all 2598960 iterations? At 100 per second, that's still about a third of a day.

In cribbage, order is important contrary to what thor said earlier. The position of 1 card determines its eligibility for "right-jack" so there really are 12,994,800 hands that need to be considered. Even still, it is possible to both generate and score all those hands in under 15 minutes using pure perl. This would encompass everything thor wanted to do and a lot more.

Cheers - L~R

In cribbage, order is important contrary to what thor said earlier.
While you're correct in that order matters, you and I are not disagreeing. My original problem was to prove that all hands that contained a 5 had at least two points. If knobs is obtained, then a jack was cut. With at least one 5 in the hand, this will yield 2 points for the fifteen, thus satisfying the original problem.

thor

The only easy day was yesterday

Create A New User
Node Status?
node history
Node Type: note [id://458236]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (13)
As of 2016-05-04 13:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
What font do you use for programming?

Results (78 votes). Check out past polls.