Probability that the third drawn ball is white if the first two are white

833 Views Asked by At

The box contains 10 white balls and 10 black balls. 3 balls are drawn one by one from the box without replacement.
What is the probability that third ball is white given that the first two are white?

My solution:
A - the third ball is white
B - the first two balls are white
The wanted probability is the conditional probability

$\Pr(A|B) = \frac{\Pr(A\cap B)}{\Pr(B)}$
$\Pr(A\cap B) = \frac{10\cdot 9\cdot 8}{20\cdot 19\cdot 18}$ - here I'm choosing 3 white balls and dividing by the total number of ways to choose 3 balls
$\Pr(B) = \frac{10\cdot 9\cdot 18}{20\cdot 19\cdot 18}$ - here I'm choosing 2 white balls and third - any of 18 remaining and dividing by the total number of ways to choose 3 balls
Then $\Pr(A|B) = \frac{8}{18} = \frac{4}{9} = 0.\overline{4}$

In order to ensure that this is correct solution I've done a simulation of the process described in the task. The code is as follows (Python):

import random
def ex():
    #make a list with 10 "w"'s and 10 "b"'s
    balls = ['w']*10 + ['b']*10
    #pop three random elements from the list
    a = balls.pop(random.randint(0, len(balls)-1))
    b = balls.pop(random.randint(0, len(balls)-1))
    c = balls.pop(random.randint(0, len(balls)-1))
    if a == b == 'w':
        return c == 'w'
    return 0

exps = 10**5
sucs = 0
for i in range(exps):
    sucs += ex()
print(sucs / exps)

The simulation gives 0.10509 which is far from $\frac{4}{9}$.
What is wrong and where?

3

There are 3 best solutions below

4
On BEST ANSWER

The probability is obviously $\frac{8}{18}$, yes.

The problem with your code is that it will return a 'success' if and only if all three balls are white, i.e. you are calculating $P(W1 \land W2 \land W3)$ (which is $\frac{10}{20} \cdot \frac{9}{19} \cdot \frac{8}{18} \approx 0.10526$ so that coincides with what you experimentally found).

However, you should be calculating $P(W3|W1 \land W2)$

So, you need to count how many times you get $a==b== \ 'w'$ (which out of $100,000$ trials should be about $\frac{10}{20} \cdot \frac{9}{19} \cdot 10^5 \approx 23,684$ times) and out of those how many times you get $c== \ 'w'$

0
On

No need to go into conditional probability.

You know that two white balls have been drawn. i.e. 10 black balls, 8 white balls are left.

So probability of drawing white ball on 3rd draw is $8\over{18}$ i.e. $4\over{9}$

So your code's got a bug.

0
On

This code should then get the right answer for what you are looking for, it is admittedly a lot slower...

import random
exps = 10**5
sucs = 0

def ex():
    while True:
        #make a list with 10 "w"'s and 10 "b"'s
        balls = ['w']*10 + ['b']*10
        #pop three random elements from the list
        a = balls.pop(random.randint(0, len(balls)-1))
        b = balls.pop(random.randint(0, len(balls)-1))
        c = balls.pop(random.randint(0, len(balls)-1))
        if a == b == 'w':
            return c == 'w' #only way to exit is if a == b == 'w', then we check if c == 'w' and return


for i in range(exps):
    sucs += ex()
print(sucs / exps)