- #1

- 448

- 18

- Homework Statement
- What is the probability that at least 2 cards of the same value will be next to each other in a pack of cards?

- Relevant Equations
- I don't have one yet

Not really a homework question. I was reading a book on card tricks and it said that it's almost certain that in a shuffled deck of cards, there will be at least two consecutive cards of the same value. I just wanted to know the actual probability of that. So, here's my question: in a standard deck of 52 cards, what is the probability that

This is what I did: I simulated 5 million shuffles in Python, and at least 2 consecutive cards had the same value in 95.45% of those 5 million trials. I'd still like to know the closed form of the probability. Here's my Python code in case anyone wants to check it out.

*at least*2 cards of the same value will be next to each other? Now I get it that I need to calculate the probability that no two consecutive cards have the same value, and then subtract that from 1. But I am stuck.This is what I did: I simulated 5 million shuffles in Python, and at least 2 consecutive cards had the same value in 95.45% of those 5 million trials. I'd still like to know the closed form of the probability. Here's my Python code in case anyone wants to check it out.

**Mentor note**: code from link above added to post
Python:

```
from random import shuffle
values = ['A', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K']
cards = 4 * values # create 52 cards (only the 52 values are required; suits are irrelevant and not needed)
trials = 5_000_000
desired_outcome = 0
for _ in range (trials):
shuffle(cards) # shuffle the cards using random.shuffle()
for i in range (51):
if cards[i] == cards[i+1]:
desired_outcome += 1
break
print(f'Desired Outcome = {desired_outcome :,} times = {desired_outcome*100/trials :.2f}%')
```

Last edited by a moderator: