# How many ways to make a straight flush in 7 card poker? (53 card deck with joker)

I can't seem to figure this one out.

There are 53 cards in this deck, 1 joker that can assume any rank, choose from 7 cards.

This is what I got:

$$\binom{9}{1}\binom{4}{1}\binom{5}{4}\binom{46}{2} = 186,300$$

I multiplied 9 by 4 to get the amount of five card straights. I realized the joker can only assume the rank of the highest four ranks of the straight, else it will form a higher straight. I reasoned there are four high ranks plus the joker, and I want to choose any four of those five to complete the set. Next I excluded the five cards in the straight plus the one that wasn't chosen. I also took out the next consecutive highest card, so a higher flush doesn't form. After this there was 46 of 53 cards remaining to choose the last two cards from.

However, I have looked at multiple tables online. All of these tables get 184,832 as their solution. I'm not sure where I went wrong here, any advice?

• Can the joker be used to serve as any one of the cards in the deck? If this is the case I assume the hand cannot contain the same card twice (i.e. the joker is used for one card in the hand). It is possible that you have not taken this fully into account and that could explain why you overcounted. Apr 4, 2017 at 22:36
• One issue is that some hands can make more than one straight flush. I would presume all your online tables would not want to double- or triple-count such hands: they only want to count hands with which it is possible to form a straight flush. Your analysis seems like an obscure and convoluted way of handling this, and therefore is suspect: try for a more straightforward method. Test it on a smaller version of this problem, such as a deck with one suit, five ranks plus a joker, four-card hands, and three-card straights, where you can readily enumerate all the solutions as a check.
– whuber
Apr 19, 2017 at 23:11

## 3 Answers

I found 210,964 hands of 7 cards that contain at least one 5-card straight flush, using the following Python 3 program, which takes about 21 minutes to run on my laptop.

from itertools import combinations
from functools import lru_cache

JACK, QUEEN, KING, ACE = 11, 12, 13, 14

N_HANDS = 154143080       # 53 choose 7

deck = ["JOKER"] + [(rank, suit)
for rank in range(2, ACE + 1)
for suit in range(4)]
assert len(deck) == 53

no_joker_straights = {
tuple(range(i, i + 5)) for i in range(2, ACE + 1) if i + 4 <= ACE}
no_joker_straights.add((2, 3, 4, 5, ACE))
joker_straights = {
tuple(sorted(set(hand) - set([x])))
for hand in no_joker_straights
for x in hand}

found = 0
divisor = N_HANDS // 100

@lru_cache(maxsize=None)
def is_straight_flush(hand):
joker = False
if "JOKER" in hand:
joker = True
hand = list(hand)
hand.remove("JOKER")
# Check that it's a flush.
if len({suit for (_, suit) in hand}) != 1:
return False
# Check that it's a straight.
return (tuple(rank for rank, _ in hand) in
(joker_straights if joker else no_joker_straights))

for i, hand in enumerate(combinations(deck, 7)):
if i % divisor == 0:
print("{}% complete ({:,})".format(i // divisor, found))
for subhand in combinations(hand, 5):
if is_straight_flush(subhand):
found += 1
break

print("{:,} straight flushes in {:,} hands".format(found, N_HANDS))

• +1 This looks correct. Thank you for checking and improving your result, because it helped me arrive at the right value, too.
– whuber
Apr 20, 2017 at 22:26

If you think about how you might go about writing efficient code to enumerate all the straight flushes, you can develop a mathematical formula--which is the ultimate efficiency! I will not in fact bring you all the way to such a formula, because it's a nuisance. Instead, I will show how to short-circuit both the complicated combinatorial maneuvers and computationally-intensive brute-force searches to find a happy medium in which you can be reasonably certain of getting the correct answer while not having to work too hard to do so.

First, note that it's not possible for a seven-card hand to hold straight flushes (SF) of two different suits, because (apart from a possible Joker) there have to be at least four suited cards in the SF. Therefore we need only count the straight flushes of a given suit, and multiply that count by four to get the total.

Pick a suit, once and for all. Let's divide the problem of finding all the SFs in that suit according to how many cards of that suit (counting the Joker) actually appear in the hand. Since a SF consists of five cards, the (mutually exclusive) possibilities are $7$, $6$, and $5$ cards. Let's count each case. To simplify the notation, let the ranks be 1 (the ace also written as A), 2, ..., 9, T=10, J=11, Q=12, and K=13. The ace can count as rank 14 if that helps to form a SF.

• With $5$ cards, they are the SF. Without the Joker, their sorted ranks can be 12345, 23456, ... through TJQKA, of which there are $10$ possibilities. If one of them is the Joker, we have to take care not to double-count. Sort them lexicographically, replacing the Joker (*) with the smallest value that can create a SF. For instance, 3456* is interpreted as 23456 rather than 34567. In this fashion we obtain five more possible ways of forming 12345 (namely, *2345, 1*345, 12*45, 123*5, and 1234*), but only four additional ways of forming the other SFs. (E.g., the five SFs beginning with 3 are 34567, *4567, 3*567, 34*67, and 345*7: the set 3456* would be interpreted as *3456, which begins with 2!) That produces $10 + 4(10) + 1 = 51$ distinct possibilities. There are, independently of these possibilities, $\binom{39}{2}$ ways to select the cards in one of the other three suits.

• With $6$ cards, the counting gets more complicated but is not fundamentally different. Note that we cannot blithely count the SFs without a Joker and then multiply that by $6$ to account for the six possible positions a Joker could substitute for. (This is where other attempts at a solution have foundered.) The problem is that this counts some hands multiple times. As an example, consider the hands 89TJQK and 8TJQKA. By substituting a Joker (*) for the 9 in the first and for the Ace in the second, we obtain identical hands 8TJQK*. Instead, we can order the SFs as before, by the start of the lowest SF that can be formed from the cards, but this time we have to multiply the counts by the number of value which that spare sixth card can have without creating a SF with a lower starting value. The resulting count is $356$. It breaks down into $49$ ways to product a SF beginning with an ace, $35$ SF's beginning with 2, and $34$ each of all the rest. As before, this value of $356$ has to be multiplied by the $\binom{39}{1}$ ways to select the seventh card from the other $39$ cards not in the suit.

• With $7$ cards, the counting is further complicated because there are two spare cards floating around, but no new ideas are needed. The actual count is $1066$. It breaks down, ordered by the start of the SF, into $176, 105, 99,$ and $98$ each of the remaining SFs (beginning with 4 or greater).

What's the point of just quoting these counts? Well, if we wish, we can obtain the two difficult counts (for $6$ and $7$ suited cards) by brute force enumeration. The number of seven-card hands that can be drawn from a Joker and only the $13$ cards of one suit is a mere $\binom{13+1}{7} = 3432$. Instead of having to search through hundreds of millions of possibilities ($\binom{53}{7} = 154\ 143\ 080$), we can perform an almost instantaneous search, once. The searches over six-card and five-card hands are even shorter.

The total number of SFs, allowing one Joker, therefore is

$$k = 4\left(51\binom{39}{2} + 356\binom{39}{1} + 1066\right) = 210\ 964.$$

From this we obtain the chance of drawing a straight flush as

$$\frac{k}{\binom{53}{7}} = \frac{210\ 964}{154\ 143\ 080} = \frac{4057}{2\ 964\ 290} = 0.00136883\ldots\ .$$

Because it's rather a nuisance to work out the values $356$ and $1066$ with formulas, this solution offers a nice combination of tools: use a little combinatorial reasoning to (greatly) reduce the computation, and then use the computer to avoid working too hard.

Readers who have come this far will be pleased to note that this answer agrees with the one posted earlier by Kodiologist.

• I'd give an extra +1 if I could for the explanation as to the pitfalls of 6 & 7 cards, which I clearly fell into. Thanks, @whuber. Apr 20, 2017 at 23:24
• "If one of them is the Joker, it may appear in any one of the five places--and all those possibilities are distinct. That gives 5 × 10 = 50 SFs." — Shouldn't it be 6 × 10, because in addition to the 5 possible positions of the joker, there's a distinct 6th possibility in which none of the 5 cards is a joker? Apr 21, 2017 at 0:15
• @Kodiologist I have inspected my results carefully and now understand the formula in detail. I, too, overlooked some possibilities, and our results agree again!
– whuber
Apr 21, 2017 at 15:44
• @whuber Nice! Overall, this was a surprisingly difficult problem. Apr 21, 2017 at 17:13
• @whuber Only the last one counts and it is close. Thanks for your time. I don't believe 186,300. I found a source that agrees with you. Apr 21, 2017 at 23:02

Start with how many ways to make a straight
There are 10 as an Ace can be used as low (wheel)
No blocker on an Ace high straight
On any other straight you cannot have the next higher card above or it turns into another straight

    1   2   3   4   5   6   7   8   9   10
A   x   b
K   x   x   b
Q   x   x   x   b
J   x   x   x   x   b
T   x   x   x   x   x   b
9       x   x   x   x   x   b
8           x   x   x   x   x   b
7               x   x   x   x   x   b
6                   x   x   x   x   x   b
5                       x   x   x   x   x
4                           x   x   x   x
3                               x   x   x
2                                   x   x
A                                       x


start withOUT the joker

$$\frac {\binom{4}{1} \binom{47}{2} + \binom{4}{1} \binom{9}{1} \binom{46}{2} } { \binom{52}{7} } = \frac {41584} {133784560} = 0.00031083 \approx \frac {1} {3217}$$

The number for no joker is correct.

Now for the joker

Now have 53 cards
Joker can be used in any straight
Now have 6 ways - raw and joker in any of the five positions

With jokers the possibilities are:

    1   2   3   4   5   6   7   8   9   10
A   x   j   x   x   x   x
K   x   x   j   x   x   x
Q   x   x   x   j   x   x
J   x   x   x   x   j   x
T   x   x   x   x   x   j
9
8
7
6
5
4
3
2
A

1   2   3   4   5   6   7   8   9   10
A                       j
K   x   j   x   x   x   x
Q   x   x   j   x   x   x
J   x   x   x   j   x   x
T   x   x   x   x   j   x
9   x   x   x   x   x
8
7
6
5
4
3
2
A

1   2   3   4   5   6   7   8   9   10
A
K                       j
Q   x   j   x   x   x   x
J   x   x   j   x   x   x
T   x   x   x   j   x   x
9   x   x   x   x   j   x
8   x   x   x   x   x
7
6
5
4
3
2
A


Notice under ace high replacing the bottom card with a joker would make a different straight as then would use the joker as high card and that hand was used in the set above. So joker only adds 4 more hands to the raw.

Also have different number of blockers. Don't use the joker then two blockers to make the next higher. Use the joker and only one blocker.

$$\frac { \binom{4}{1} \binom{6}{1} \binom{48}{2} + \binom{4}{1} \binom{1}{1} \binom{9}{1} \binom{46}{2} + \binom{4}{1} \binom{4}{1} \binom{9}{1} \binom{47}{2} } { \binom{53}{7} } = \frac {27072 + 37260 + 155664} {154143080} = \frac {219996} {154143080} = 0.0014272194 \approx \frac {1}{700.66}$$

Pointed out in a comment this is missing blockers on the bottom

23 56 89 *
23*56
56*89


Note sure if this is the correct way to look at blockers on the bottom but it is a start

    1   2   3   4   5   6   7   8   9   10
A   x   j   x   x   x   x
K   x   x   j   x   x   x
Q   x   x   x   j   x   x
J   x   x   x   x   j   x
T   x   x   x   x   x   j
9           b   b   b   b
8               b   b   b
7                   b   b
6                       b
5
4
3
2
A

1   2   3   4   5   6   7   8   9   10
A   bb  b   b   b   b   j
K   x   j   x   x   x   x
Q   x   x   j   x   x   x
J   x   x   x   j   x   x
T   x   x   x   x   j   x
9   x   x   x   x   x
8       b   b   b   b
7           b   b   b
6               b   b
5                   b
4
3
2
A

1   2   3   4   5   6   7   8   9   10
A
K   bb  b   b   b   b   j
Q   x   j   x   x   x   x
J   x   x   j   x   x   x
T   x   x   x   j   x   x
9   x   x   x   x   j   x
8   x   x   x   x   x
7           b   b   b
6               b   b
5                   b
4
3
2
A

1   2   3   4   5   6   7   8   9   10
A
K
Q
J
T
9   bb  b   b   b   b   j
8   x   j   x   x   x   x
7   x   x   j   x   x   x
6   x   x   x   j   x   x
5   x   x   x   x   j   x
4   x   x   x   x   x
3           b   b   b
2               b   b
A                   b

1   2   3   4   5   6   7   8   9   10
A
K
Q
J
T
9
8   bb  b   b   b   b   j
7   x   j   x   x   x   x
6   x   x   j   x   x   x
6   x   x   x   j   x   x
4   x   x   x   x   j   x
3   x   x   x   x   x
2           b   b
A               b

1   2   3   4   5   6   7   8   9   10
A
K
Q
J
T
9
8
7   bb  b   b   b   b   j
6   x   j   x   x   x   x
5   x   x   j   x   x   x
4   x   x   x   j   x   x
3   x   x   x   x   j   x
2   x   x   x   x   x
A           b

1   2   3   4   5   6   7   8   9   10
A
K
Q
J
T
9
8
7
6   bb  b   b   b   b   j
5   x   j   x   x   x   x
4   x   x   j   x   x   x
3   x   x   x   j   x   x
2   x   x   x   x   j   x
A   x   x   x   x   x

• Your last calculation does not seem correct. Could you explain the reasoning behind it?
– whuber
Apr 19, 2017 at 23:07
• @whuber Could you tell me why you think it is not correct? Now have 6 cards to make the 5 card straight. Apr 20, 2017 at 4:36
• Briefly, the method is too simplistic, unexplained, and not checked. (1) There's no explanation and the formula seems too simple for the problem. (2) There are $53$ cards but you divide by $\binom{52}{7}$. (3) Your result (even when you fix the error in #2) is far from the values quoted in the question, which correspond to a chance of $0.001199$. (4) Your value differs significantly from a simulation of half a million deals, which gave $0.00128\pm 0.0001$ for the chance of a straight flush.
– whuber
Apr 20, 2017 at 14:28
• @whuber Will fix the 52. I will run a simulation if I get a time. Apr 20, 2017 at 15:02
• Maybe one way to see the problem with your approach is that you are counting straight flushes, but you aren't accounting for what might actually occur within a hand. It might be illuminating to consider suited hands like 235689* (* is the Joker). The problem with such hands is that they can be more than one straight flush: if you let * stand for the 4, this is a 23456 straight flush, but if you let * stand for the 7, this is a 56789 straight flush.
– whuber
Apr 22, 2017 at 19:10