Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re^2: Generating all 5-card hands

by thor (Priest)
on May 18, 2005 at 15:58 UTC ( #458263=note: print w/ replies, xml ) Need Help??


in reply to Re: Generating all 5-card hands
in thread Generating all 5-card hands

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


Comment on Re^2: Generating all 5-card hands
Re^3: Generating all 5-card hands
by merlyn (Sage) on May 18, 2005 at 16:03 UTC
      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

        thor,
        What do you mean suit doesn't matter? In cribbage, you get 4 points if all 4 cards in your hand are the same suit. If you want to prove that no hand with a 5 isn't worth at least 2 points you HAVE to consider suits. You can easily use Re: Iterating over combinations to generate the hands. The hard part is the scoring.

        On the other hand, it is a lot easier to prove that there is a hand of 5 cards containing at least 1 five that is a total of less than 2 points.

        • 4 cards (your hand) must not all be of the same suit
        • Must not contain any cards with a value of 10
        • Must not containing any combination (excluding the 5) whose sum is 10
        • Must not contain any 2, 3, or 4 of a kind
        • Must not have any sequence of greater than 2
        I don't have an implementation yet, but it certainly does reduce the problem set.

        Cheers - L~R

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://458263]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (12)
As of 2014-12-19 15:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (85 votes), past polls