# Probability of winning the game “1-2-3”

Ok, game is as follow, with spanish cards (you can do it with poker cards using the As as a 1)

You shuffle, put the deck face bottom, and start turning the cards one by one, saying a number each time you turn a card around ---> 1, 2, 3; 1, 2, 3; etc. If when you say 1 a 1 comes out, you lose, same with 2 and 3. If you finish the deck without losing, you win.

I know some basics of probabilities, but is there a way to calculate the probability of winning the game, given a random shuffled deck?

-
Can you name any number $1 \to 13$ while turning the cards? I.e. whats the range of the numbers you may name? – JohnWO Jun 7 '13 at 17:28
Is the player allowed to say 1, 2, or 3 at random or does he/she always have to follow the sequence 1,2,3,1,2,3,...? – iX3 Jun 7 '13 at 17:52
If one wants something more general; If one could name any numerical value of a card in the deck, i.e.: If there are 52 cards in the deck, divided over 4 suits, which range from $1 \to 13$, counting $\text{Ace's}$ as $1$, you would have $13$ different choices. So the chances of loss are approx.: $\frac{d}{r^2\;s}$, where $d$ denotes the number of cards left in the deck, and $r$ denotes the numberical range of the cards in the deck, and $s$ denotes the number of suits. – JohnWO Jun 7 '13 at 17:54
Monte Carlo method shows the probability of $\approx 0.008$, so the approximation with $\left(\frac 2 3\right)^{12}$ is for this deck size already good enough. – Harold Jun 7 '13 at 18:32
Yes, i am sorry, you can't say any number, you have to say JUST 1, 2, 3, 1, 2, 3, 1, 2, 3, repeat. – Pphax Jun 7 '13 at 22:17

For $i,j\in\{1,2,3\}$, let $a_{i,j}$ denote the number of $i$ cards being dealt with number $j$ spoken. We have $\sum_j a_{i,j}=4$ and for a winning game $a_{i,i}=0$. The number of winning positions for a given $(a_{i,j})$ is $$\frac{18!}{a_{2,1}!a_{3,1}!(18-a_{2,1}-a_{3,1})!}\cdot\frac{17!}{a_{1,2}!a_{3,2}!(17-a_{1,2}-a_{3,2})!}\cdot\frac{17!}{a_{1,3}!a_{2,3}!(17-a_{1,3}-a_{2,3})!}.$$ We need to sum this over all $(a_{i,j})$ and divide by the total count $$\frac{52!}{4!4!4!40!}.$$ (Actually, we need just let $a_{1,2}, a_{2,3}, a_{3,1}$ run from $0$ to $4$ and this determines $a_{1,3}=4-a_{1,2}$ etc.) The final result is $$p=\frac{58388462678560}{7151046448045500}=\frac{24532967512}{3004641364725}\approx 0.008165$$ (I just noted that Harold has performed a Monte Carlo simulation with matching result)

-
I did calculate the precise probability too, also using combinatorics, but this formula looks so terrifying for me :) I like the approximation explained by Byron Schmuland more. But it would be intresting to find some simplier way for a common case, it should defenitely exist. – Harold Jun 7 '13 at 19:16

Another update:

As explained in the paper below, you can use rook polynomials to solve such problems. Playing with a full deck of 52 cards we will call "one" 18 times, we will call "two" 17 times, and we will call "three" 17 times. The forbidden positions in the 52 by 52 board consist of three "independent" complete rectangles; one $18\times 4$ and the other two $17\times 4$.

The rook polynomial for a full $m\times n$ rectangle with $m\geq n$ is $$\sum_{k=0}^n{m\choose k}\, {n!\over (n-k)!}\, x^k.$$

Multiply the polynomials for these three rectangles to give us the rook polynomial for our problem
$$R(x)=(1+73440x^4+19584x^3+1836x^2+72x)(1+57120x^4+16320x^3+1632x^2+68x)^2.$$

The number of winning deck orders is $$\int_0^\infty x^N R(-1/x) \exp(-x)\,dx$$ so the probability is this divided by $N!$, i.e. $$\mathbb{P}(\text{win})= 24532967512/3004641364725= 0.008165023553.$$

Reference: F. F. Knudsen and I. Skau, On the Asymptotic Solution of a Card-Matching Problem, Mathematics Magazine 69 (1996), 190-197.

Update: The solution below is for a simplified version of the problem where you work with a deck of size 12: four each of ace, deuce, and trey.

This is a problem in generalized derangements and joriki's answer here tells you what to do. In general, the number of deck orders that lead to a win is $$\int_0^\infty L_{n_1}(x)\cdots L_{n_r}(x)\,\mathrm e^{-x}\mathrm dx.$$

In this problem, we have $r=3$ and $n_1=n_2=n_3=4$. The fourth Laguerre polynomial is $L_4(x)=(x^4-16x^3+72x^2-96x+24)/24$. Raising this to the third power and integrating against $\exp(-x)$ gives $346$. That is, there are $346$ ways to order the deck that give a win.

Divide this by the total number of orders $12!/(4!)^3$, to give $$\mathbb{P}(\text{win})=173/17325=0.00998.$$

-
Why does your answer differ significantly from Harold's Monte Carlo result? – Hagen von Eitzen Jun 7 '13 at 19:05
I am playing with a deck of size 12: four each of ace, deuce, trey. – Byron Schmuland Jun 7 '13 at 19:07
Now I'm playing with a full deck! – Byron Schmuland Jun 7 '13 at 20:04
Thank you Byron, i chose Hagen's answer because he answered first, but yours is very clear too. – Pphax Jun 7 '13 at 22:44
Hi Byron -- I used this to give a simpler answer to this question, which had come up again as a duplicate today. – joriki Jul 12 '15 at 0:51

This is a hard question, if the player is using optimal strategy rather than just cycling through numbers.

For example, once the deck is down to 2 cards the player is guaranteed a win, because those two cards are known and (even if they're different) the player can name the third number. If the deck is down to 3 cards the player is guaranteed a win unless those last three cards are all different, in which case the player can't do better than guessing at random (2/3 chance) of winning.

Full analysis for a deck of size 6: 2 each of $1,2,3$.
Card 1: random, 1/3 chance of loss
Card 2: guess whatever card 1 was, 1/5 chance of loss (if top two cards are the same)
Card 3: guess either of the first two cards, 1/4 chance of loss
We now have two situations. If the first three cards are all different, there is a further 1/3 chance of loss, based on the analysis in the paragraph above, otherwise a win is assured. Each case happens half the time; two each of the four cards lead to the two cases.

Altogether, the probability of loss is: $$\frac{1}{3}+\frac{2}{3}\frac{1}{5} + \frac{2}{3}\frac{4}{5}\frac{1}{4} + \frac{2}{3}\frac{4}{5}\frac{3}{4}\frac{1}{2}\frac{1}{3}=\frac{2}{3}$$

This seems too good to be true, but there it is.

-
I may be misunderstanding, but I thought the player is required to call $1,2,3,1,2,3,1,\ldots$ in that order with no scope for strategy. – MJD Jun 7 '13 at 19:02