Brad Johnson
United States Crystal Lake Illinois

I'm looking for help deriving the general equation for the following:
Given a deck of cards composed of X suits numbered 1 to Y each, what is the probability of a randomlydealt hand of size M containing a flush of size N?
For example, say I have a deck of 6 suits numbered 1 to 10 each. (So a deck of 60 cards.) If I deal a hand of 8 random cards, what is the chance it will contain exactly 4 cards of the same suit (any suit)?
Unless I'm wrong, the same equation should be usable to get the probabilities of sets (cards of the same rank), because it's just "slicing" the deck the other way.
But I'd also like to get the general equation as above for straights (cards in sequential rank, regardless of suit) of size N, which I think is probably even more complicated.
I can't get my head around this. Any probability experts who can help out there?

Jeremy Lennert
United States California

There are X*Y cards in the deck, so C(X*Y, M) possible hands of size M.
To have exactly N cards of a specific color, you need to deal N cards of that color and MN cards of other colors; there are C(Y, N) * C(Y*(X1), MN) ways to do that.
So the odds of getting an Nlong flush of a specific suit (say, clubs) is C(Y, N) * C(Y*(X1), MN) / C(X*Y, M).
However, that's going to include some hands that also have partial flushes in another color. For instance, if you look for 8card hands with 3flushes in clubs, you're including hands that have a 3flush of clubs and a 5flush of diamonds in the same hand. If you want to exclude those because you only want to count the "best" set in the hand, things get more complicated.
Also, you might think you could count up the 3flushes in ALL suits by muliplying by the number of suitsbut there are some hands with 3flushes in multiple suits, so you'd be counting those twice.
To handle both of the preceding points, you'd probably need to calculate the number of hands with overlap and then apply the InclusionExclusion Principle.
Unless you are dealing with really big numbers, I suspect you would be better served by writing a computer program to count the hands by brute force, instead of trying to derive a closedform equation. Less chance of an error, and easier to modify to handle other cases.

Brad Johnson
United States Crystal Lake Illinois

Thanks  that overlap between multiple flushes in the same hand (the "more complicated" part) is what's messing me up. I do want to just count the "best" flush, regardless of suit. I debated doing a program to empirically count all the possible hands, but the case I'm really most interested in is C(5*12,9) = 14.8 billion hands, and that's really just too many to do on my little laptop.
I think I'm going to have to try to come up with all the possible overlapping subcases and calculate them separately.....

Jeremy Lennert
United States California

tempus42 wrote: the case I'm really most interested in is C(5*12,9) = 14.8 billion hands, and that's really just too many to do on my little laptop. You could use random sampling (Monte Carlo) to get an approximate answer much more quickly.

Pelle Nilsson
Sweden Linköping

tempus42 wrote: the case I'm really most interested in is C(5*12,9) = 14.8 billion hands, and that's really just too many to do on my little laptop......
Even your laptop probably does several billion instructions per second so iterating over 14.8 billion hands to count how many match some criteria should not take very long.
Otherwise Monte Carlo as was already suggested.

Larry L
United States Stockton California
Roll for it
I + I = 0

Inclusion/Exclusion isn't too awful for flushes as you have defined them (exactly N cards, no more, no less) since you can't have too many in your hand at once. (I think you will run into more trouble with straights, but I haven't thought it through)
If you are okay counting hands with one or more flushes in them you want:
# of hands with 1 flush (and maybe more)  # of hands with 2 flushes + # of hands with 3 flushes and so on (alternating minus/plus). Luckily that 'and so on' wont run very long, since you will run out of space in your hands really quickly.
If you want hands with exactly one flush and not two (or more) you want:
# of hands with 1 flush (and maybe more)  2 * # of hands with 2 flushes + 3 * # of hands with 3 flushes and so on.
(After you count, divide by the number of possible hands to get the probability)

Brad Johnson
United States Crystal Lake Illinois

Thanks, everyone. I was actually able to do some semimanual piecemeal calculations to come up with the percentages I wanted for one specific case, for flushes and sets at least. Much harder for straights. So I did also go ahead and wrote a little program to do some Monte Carlo estimation for some particular means I wanted. Seemed to work out ok. General equations just aren't going to be practical the way I had hoped, but I got what I needed anyway.

Peter Strait
United States Sacramento California

Also, and this is a little out there, if you consider each suit a directional axis you can exclude based on rotational symmetry. (You'll need a modern graphics card and a postgrad CS degree to pull it off, though.)

Peter Strait
United States Sacramento California

Also and more seriously (since my brain has decided it enjoys chewing on this question), you can create a "built up" probability for a given hand almost trivially*, by recursively asking, "What is the chance that the next card drawn will contribute to a straight/flush/set?" paired with treating each nonmatching card as opening a new opportunity for a separate set. (Basically "Odds of Continuing Flush N" with "Odds of starting new flush" for each successive card, branching once with each new card up to as many times as there are suits, which can then be summed; you should be able to go up to a hand size of 8 without swamping a modern PC.)
(*can be done with an BS or AS in CS. )


