# Cards - Probability of not hitting a number repeatedly when my prediction changes (1, 2, 3, 1, 2, 3, etc.)

Consider a game with a normal deck of 40 cards, that is 10 numbers for each suit.

The game is as follows:

• before every game the deck is shuffled
• I draw a card at a time without replacement, until no cards are left
• every time I draw a card I also say a number at the same time
• the number I will say is known. I always say the numbers 1, 2 and 3 in this order until the end. This means that on the first card I will say 1, on the 6th card I will say 3 and on the 40th card I will say 1.
• I lose the game if at any point the card I draw has the same rank as the number I am saying. I win if I can get to the end of the deck.

How would you compute the probability of winning at such a game?

• Inclusion Exclusion ought to work, but it will be messy (there are $12$ relevant cards that might or might not be in "bad" positions). I'd be tempted to just simulate it. Even if an analytic solution can be found, it would be good to have the simulated solution available for comparison.
– lulu
Commented Nov 13, 2023 at 18:20

A simulated one-liner solution, in R:

> set.seed(42)
> mean(replicate(1000000, sum((sample(40) %% 10) == (1:3)) == 0))


returns

0.008278


Unpacking this a bit:

• sample(40) gives a random permutation of \${1, 2, \ldots, 40}
• so reducing it mod 10 (%% 10) gives a random permutation of 0 through 9 each repeated four times
• checking for equality with 1:3 takes advantage of R's vector operations and recycling capability, so this actually returns a vector of length 40 of TRUE and FALSE according to whether the element of the shuffled deck is equal to the corresponding element in $$1, 2, 3, 1, 2, 3, \ldots, 1, 2, 3, 1$$
• the sum of that vector is the number of elements equal to TRUE (that is, matches); we check to see if it's equal to zero (== 0), repeat the experiment a million times (replicate), and return the proportion of those experiments come back TRUE (mean)

This agrees very well with HighDiceRoller's result.

Also this seems to be very close to (but not a straight duplicate of) this question, which asks about a 52-card deck.

Here's a solution using my Icepool Python probability package:

from icepool import Deck, multiset_function

deck = Deck([1, 2, 3, 4, 5, 6, 7, 8, 9, 10] * 4)

@multiset_function
def evaluate(a, b, c):
return a >= [1], b >= [2], c >= [3]

output(evaluate(deck.deal(14, 13, 13)))


You can run this in your browser here.

Here we consider 1, 2, and 3 to be "hands", and see whether each of them contains any of the corresponding rank. (After looking at the link in Michael Lugo's answer, I realized it would be more efficient to swap the roles of the hands and the ranks, but this formulation is more intuitive.) The chance of all three not containing any of the corresponding rank is

$$\frac{2005028661108720 }{241365994493904000} \approx 0.830701\%$$

Perhaps someone else will come around with a more bespoke / intelligible solution.