in reply to Generating all 5card 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.
Re^2: Generating all 5card 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 52choose5: the number of 5card 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 nonordered 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
 [reply] 

a cribbage hand is inherently nonordered
But 52choose5 is nonordered.
 [reply] 

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 misspoke 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
 [reply] 





Re^2: Generating all 5card 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 "rightjack" 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.
 [reply] 

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
 [reply] 

