# Probability that shuffled deck contains no two consecutive cards of the same suit

If a deck of 52 standard cards is completely randomly shuffled, what are the odds that not once do two cards of the same suit end up right next to each other?

Rephrasing: If I have a bag of 13 red balls, 13 blue balls, 13 yellow balls, and 13 white balls, and I keep pulling out balls without replacement, then what are the odds that I never pull a ball of the same color twice consecutively?

I've tried doing this for small sets, and looking for a rule (2 of each suit, and 3 of each suit)

I've tried to find a statistical significance to get a good estimate, or a certain pdf, or cdf to use, but I could find none.

Is there any way of finding this without massive computations?

-
This is a special case of the following: math.stackexchange.com/questions/430000/… – Nikos Δr Aug 6 '14 at 21:02

If you are willing to use massive computations, you can get the exact answer as follows based on the method in this answer. If $q(x)=\sum_{i=1}^{13} \frac{(-1)^{i-13}}{i!} {13-1 \choose i-1}x^i$, then the number of permutations with no consecutive cards of the same suit is $$\int_0^\infty q(x)^4\,e^{-x}\,dx=63394531038905867912088.$$ Dividing this by $52!/(13!)^4$ gives the probability $.000001181747431$.

-
Wow, that was much faster than I expected for an answer. Additionally, thanks for linking to helpful answers. I knew it would be small, but I did not expect almost less than 1 in 1 million. – Asimov Aug 6 '14 at 21:15
Shouldn't it be dividing by $52!$? Or is it the number of permutations assuming that the cards of the same suit are indistinguishable? – Thomas Andrews Aug 6 '14 at 21:17
@ThomasAndrews The second one: 13 Hearts, 13 Diamonds, 13 Spades, and 13 Clubs (with the values erased if you like). – Byron Schmuland Aug 6 '14 at 21:19
@Asimov I agree, the probability is lower than I expected. About 1 in 846,000. – Byron Schmuland Aug 6 '14 at 21:27

It's not that massive a computation. Let $Q(a,b,c,d)$ be the probability that the top card isn't the first suit and no two adjacent cards share a suit, given that there are $a$ cards of the first suit left in the deck, $b$ of the second, etc., and the deck is thoroughly shuffled. Then the probability you want is $Q(12,13,13,13)$ (having drawn the top card and identified its suit, whatever it was, as the "first suit"). The recursion is $$Q(a,b,c,d)=\frac{bQ(b-1,a,c,d)+cQ(c-1,a,b,d)+dQ(d-1,a,b,c)}{a+b+c+d},$$ with boundary condition $Q(0,0,0,0)=1$. The following Python code calculates the value for any values of $a,b,c,d$:

def q(a,b,c,d,cache={(0,0,0,0):1.0}):
if a<0: return 0.0
if (a,b,c,d) in cache: return cache[(a,b,c,d)]
sm = (b*q(b-1,a,c,d) + c*q(c-1,a,b,d) + d*q(d-1,a,b,c)) / (a+b+c+d)
cache[(a,b,c,d)] = sm
return sm


Once defined, q(12,13,13,13) returns 1.1817474309603094e-06 almost instantly.

-
Thats a very clever formula you derived! I like this – frogeyedpeas Aug 6 '14 at 21:47

I wouldn't call this by any means fast (its exptime) but its quite a bit more efficient than attempting to just brute force enumerate

Denote the the balls as "r", "b", "y", and "w" respectively

Denote pulling out the balls as assembling a sequence of "r", "b", "y" ,"w" such that there are 13 of each

We are looking for the number of scenarios where no 2 of the same color are found in a row

This can be computed as

$$1 - \frac{number \ where \ least \ 2 \ are \ found}{total}$$

So now the total is a trivial excercise to compute as it is $$\frac{52!}{13!13!13!13!}$$

Based on the permutation formula

Now to find the number where at least 2 are present will require us to exploit an inclusion exclusion principle

We consider an empty of sequence of balls with locations $a_1, a_2 ... a_{52}$

Now for a start we can pick any two consecutive number $i,j$ and assign them the same color. From here we can ask what are all the possible permutations. In doing so however we will see some overcounting occur. Consider the following smaller case of 4 reds, 1 yellow, 1 blue

$$rrybrr$$

is a sequence which both the $rra_3a_4a_5a_6$ and $a_1a_2a_3a_4rr$ sequence count. Thus we need to remove it from the sum of combinations of these two sequences.

But now consider the more involved case of 4 reds, 2 yellows, 1 blue

$$rryybrr$$

Is counted by $rra_1a_2a_3a_4a_5a_6a_7$, $a_1a_2yya_5a_6a_7$, and $a_1a_2a_3a_4a_5rr$ which means that if we add up the counts of these three combos we have counted it 3 times, but then if we take a pair of sequences: find the intersection and then subtract we have subtracted it 3 times, in other words we forgot to count it.

This reveals to us a more general inclusion exclusion rule will be necessary and shows us an algorithm for efficiently computing your problem

Create all the different possible empty sequences that can be constructed by using only 2 of the same color placed consecutively and the remaining 50 spots blank.

Now from this generate the set of possible "intersections" of 2 sequences (ex: $rra_3$ and $a_1rr$ can be intersected to form $rrr$ but $bba_3$ and $rra_3$ cannot be intersected since that would require one of the positions to be simaltaneously red and blue.

Now generate the set of intersections of 3 original sequences, 4 original sequences, etc...

Now for each sequence you have made (including those generated from intersections) count the number of permutations of remaining elements possible

Then sum up all the first case sequence numbers, subtract the 2-intersection numbers, add 3 intersection numbers, subtract 4-intersection numbers etc... all the way down the line

The result will be the total number of sequences where at 2 of the same color are guaranteed to be next to each other, without any overcounting. Call this number N

$$1 - \frac{N (13!)^4}{52!}$$

Is the answer you are looking for

If we denote $u_i$ as a sequence generated, $u_i \cap u_j$ as the intersection of the two sequences (if possible) and null if not possible and lastly $P(u_i)$ equals the number of permutations possible for some argument inside which is a sequence or intersection of sequences (this returns 0 if the intersection inside is Null)

Then the total is

$$\sum_{i = 1}^{total \ sequences \ of \ 2} \left( (-1)^{i+1}\sum \left[P\left(\cap_{i \ elements \in U} \right] \right) \right)$$

-