PMF of total score in a card matching game

174 Views Asked by At

Consider a deck of cards with ​$N$​ different playing cards equally distributed among $M$ suits (e.g., $N=52, M=4$). You draw all the cards without putting any back. After the first card, each time you pick a card, you compare it to the previous card. If the suits match, you get ONE point; otherwise, you get no point. Suppose $P$ is the total points you get at the end of this process.

I am trying to calculate the PMF of $P$ so that I can calculate some statistics such as mean, standard deviation, etc. Here what I've gone so far:

Suppose $P_i, ~~i=1, 2, ..., N$ is the value of $P$ at the end of $i$th draw. Obviously, $P_1=0$. Also, suppose $m_i\in\{1, 2, ..., M\}, ~~i=1, 2, ..., N$ is the suit of the $i$th card that we have drawn. According to the rules, $P_{i+1} = P_i + 1$ if and only if $m_{i+1} = m_i$, i.e., $Pr(P_{i+1} = P_i + 1)=Pr(m_{i+1} = m_i)$.

Let's consider $M=52, N=4$. The probability of picking the first card is $Pr(m_1=k)=\frac{M}{N}=\frac{1}{13}, ~~k=1, 2, 3, 4$. For the second draw, we have:

$Pr(m_2=k)= \begin{cases} \frac{\frac{M}{N}-1}{N-1}=\frac{12}{51} &~~ \text{$k=m_1$} \\ \frac{\frac{M}{N}}{N-1}=\frac{13}{51} &~~ \text{$k\neq m_1$} \\ \end{cases}$ $~~~~~~$ $\Rightarrow Pr(P_{2} = P_1 + 1)=Pr(m_2=m_1)=\frac{12}{51}$

However, I can't proceed with the third and higher draws as I should include th previous cards until the first one into the expression.

I have used the following MATLAB code to simulate the experiment:

n = 1e6; N = 52; M = 4;
P = zeros(1, n);
for i = 1:n
    I = randi([1 M], 1, N);
    P(i) = sum(([I(2:end), 0]-I)==0);
end
disp(['Mean of P for N = 52 and M = 4:  ' num2str(mean(P))]);
disp(['Standard deviation of P for N = 52 and M = 4:  ' num2str(std(P))]);
disp(['Pr(P>12 | P>6) for N = 52 and M = 4:  ' num2str(sum(P>12)/sum(P>6))]);
1

There are 1 best solutions below

10
On BEST ANSWER

I’ll use $R=\frac NM$ for the number of ranks so as not to have to carry around that fraction.

Consider the indicator variable $I_k$ for $1\le k\lt N$ that is $1$ if the suits of cards $k$ and $k+1$ match and $0$ otherwise. Then the number of matches is $X=\sum_{k=1}^{N-1}I_k$. Using the linearity of expectation, the expectation of $X$ can be calculated as

\begin{eqnarray} E[X] &=& E\left[\sum_{k=1}^{N-1}I_k\right] \\ &=& \sum_{k=1}^{N-1}E\left[I_k\right] \\ &=& (N-1)\frac{M\binom R2}{\binom N2} \\ &=& R-1\;. \end{eqnarray}

So for a standard deck of $52$ cards in $4$ suits and $13$ ranks, this would be $12$.

The variance can be expressed in terms of expectations and calculated similarly:

\begin{eqnarray} \operatorname{Var}[X] &=& E\left[X^2\right]-E\left[X\right]^2 \\ &=& E\left[\left(\sum_{k=1}^{N-1}I_k\right)^2\right]-(R-1)^2 \\ &=& E\left[\sum_{j,k=1}^{N-1}I_jI_k\right]-(R-1)^2 \\ &=& \sum_{j,k=1}^{N-1}E\left[I_jI_k\right]-(R-1)^2 \\ &=& (N-1)E\left[I_1I_1\right]+2(N-2)E\left[I_1I_2\right]+(N-2)(N-3)E\left[I_1I_3\right]-(R-1)^2 \end{eqnarray}

In the first term, $I_1I_1=I_1$, so this is just $E[X]=R-1$. In the second term, $I_1$ and $I_2$ are both $1$ if the suits of three consecutive cards match, with probability

$$ \frac{M\binom R3}{\binom N3}=\frac{MR(R-1)(R-2)}{N(N-1)(N-2)}=\frac{(R-1)(R-2)}{(N-1)(N-2)}\;. $$

In the third term, $I_1$ and $I_3$ are both one if either all four cards involved are of the same suit, with probability

$$ \frac{M\binom R4}{\binom N4}=\frac{MR(R-1)(R-2)(R-3)}{N(N-1)(N-2)(N-3)}=\frac{(R-1)(R-2)(R-3)}{(N-1)(N-2)(N-3)}\;, $$

or the two cards for $I_1$ are of one suit and the two for $I_3$ are of another, with probability

$$ \frac{M(M-1)\binom R2\binom R2}{\binom N2\binom{N-2}2}=\frac{M(M-1)R^2(R-1)^2}{N(N-1)(N-2)(N-3)}=\frac{(M-1)R(R-1)^2}{(N-1)(N-2)(N-3)}\;. $$

Putting it all together, we have

\begin{eqnarray} \operatorname{Var}[X] &=& R-1+\frac{2(R-1)(R-2)}{N-1}+\frac{(R-1)(R-2)(R-3)}{N-1}+\frac{(M-1)R(R-1)^2}{(N-1)}-(R-1)^2 \\ &=& \frac{(N-R)(R-1)}{N-1}\;. \end{eqnarray}

So for a standard deck of $52$ cards in $4$ suits and $13$ ranks, this would be $\frac{156}{17}\approx9.18$. (The standard deviation is the square root of the variance.) Here’s Java code that checks these results by simulation.


P.S.:

Here’s Java code that calculates the exact probability distribution. The result for a standard deck of $52$ cards in $4$ suits and $13$ ranks is (in the range where the probabilities are at least $0.1\%$):

\begin{array}{c|cc} x&P(X=x)\\\hline 4&0.3\%\\ 5&0.7\%\\ 6&1.8\%\\ 7&3.5\%\\ 8&5.8\%\\ 9&8.6\%\\ 10&11.1\%\\ 11&12.7\%\\ 12&13.1\%\\ 13&12.1\%\\ 14&10.1\%\\ 15&7.7\%\\ 16&5.3\%\\ 17&3.4\%\\ 18&1.9\%\\ 19&1.0\%\\ 20&0.5\%\\ 21&0.2\%\\ \end{array}

In particular,

$$ P(X\gt6)=\frac{423184664000229408829}{435551802585870927936}\approx97.2\%\;,\\[10pt] P(X\gt12)=\frac{25587624310904056432013593}{60410740726901793737880000}\approx42.4\%\;,\\[10pt] P(X\gt12\mid X\gt6)=\frac{946742099503450087984502941}{2171730797566177297434324375}\approx43.6\% $$