50 Challenging Problems in Probability [Part 1]: The Sock Drawer

Shelvia
4 min readNov 27, 2023

--

Hi, I’ve recently developed an interest in problems related to probability. I came across this book “Fifty Challenging Problems in Probability with Solutions” by Frederick Mosteller. I thought it would be interesting to create a series discussing these captivating problems that might arise as interview questions. Each post will feature only 1 problem, making it a series with a total of 50 parts. Let’s dive in and activate our brain cells 🧠!

Problem:

A drawer contains red socks and black socks. When two socks are drawn at random, the probability that both are red is 1/2.

Questions:
(a) How small can the number of socks in the drawer be?
(b) How small if the number of black socks is even?

Image by the author using MidJourney.

Solution:

(a) Firstly, we know that 2 socks are drawn at random, and the probability of both being red is 1/2. This statement can be expressed mathematically as the product of two probabilities: the probability of drawing a red sock on the first draw multiplied by the probability of drawing a red sock on the second draw.

Let the total number of socks be and the total number of red socks be r. Then the probability of drawing a red sock on the first draw is r/n. Since a red sock has been drawn and no replacement is made, the probability of drawing a red sock on the second draw is (r-1)/(n-1).

This can be further solved using math, but in an interview setting, applying a bit of logical reasoning may be what the interview is looking for, especially since the question only asks to find the smallest number. Even before solving this using the equation above, we should know that the total number of socks cannot be 1 because two socks are drawn, and it cannot be 2 because the probability of both socks being red is neither 0 nor 1. Therefore, we can start testing for values of n from 3 onward.

Thus, the minimum number of socks is 4.

Python Code:

n = 3   # total number of socks (at least 3)
r = 2 # min number of red socks (at least 2)
p = 0 # initialize probability of drawing 2 red socks (without replacement)

while True:
for r in range(2,r+1):
p = (r/n)*((r-1)/(n-1))
if p == 0.5:
break
if p == 0.5:
print(f'n = {n}, r = {r}')
break
n += 1
r += 1

# Output:
# n = 4, r = 3 (total socks: 4, total red socks: 3)

(b) In the previous answer, the number of black socks is 4–3 = 1 (odd). For this question, we would need to convert the equation slightly.

From this, we can obtain 2 inequalities:

We can express n as b+r where b is the number of black socks, and we obtain:

Here’s the detailed math if you’re interested:

Then we can start testing for values of even b.

Thus, the minimum number of socks if the number of black socks is even is 15+6=21.

Python code:

n = 3   # total number of socks (at least 3)
r = 2 # min number of red socks (at least 2)
p = 0 # initialize probability of drawing 2 red socks (without replacement)

while True:
for r in range(2,r+1):
if (n-r)%2 == 0:
p = (r/n)*((r-1)/(n-1))
if p == 0.5:
break
if p == 0.5:
print(f'n = {n}, r = {r}')
break
n += 1
r += 1

# Output:
# n = 21, r = 15 (total socks: 21, total red socks: 15)

And that’s all for this socks 🧦 problem. Any feedback or questions are welcome! The code is available on my Github. Check out the other problems in this series:

50 Challenging Problems in Probability

31 stories

Thank you for reading! :)

--

--

Shelvia

Researcher in Information Theory and Trustworthy AI. Addicted to puzzles and brain teasers. Interested in particle physics and neuroscience.