# How to pick the same color spheres out of two boxes

For the following problem:

There are two boxes $A$ and $B$. Box $A$ contains $3$ red, $8$ white and $13$ green spheres, while box $B$ contains $5$ red, $7$ white and $6$ green spheres. If we pick one sphere from each box at random, what is the probability that they have the same color?

I followed this way of thinking:

I assume the following events:

• $A_1:=\{ \text{Sphere from box A is red} \}, \quad \quad B_1:=\{ \text{Sphere from box B is red} \}$
• $A_2:=\{ \text{Sphere from box A is white} \}, \quad B_2:=\{ \text{Sphere from box B is white} \}$
• $A_3:=\{ \text{Sphere from box A is green} \}, \quad B_3:=\{ \text{Sphere from box B is green} \}$

Then the probability that they have the same color will be: $$P[(A_1 \cap B_1)\cup (A_2 \cap B_2)\cup (A_3 \cap B_3)]$$ But those events are both independent and mutually exclusive therefore for two events $A$ and $B$ it generally holds: $$P(A\cup B)=P(A)+P(B), \quad P(A \cap B)=P(A)P(B)$$ So our equation above is rewritten as: $$P[(A_1 \cap B_1)\cup (A_2 \cap B_2)\cup (A_3 \cap B_3)]=P(A_1)P(B_1)+P(A_2)P(B_2)+P(A_3)P(B_3)$$ which now is just a matter of arithmetics.

Anyway, my question is the following:

Is my thinking above correct? And if yes, I am pretty sure there is a faster way to go with this one. Any ideas?

Thank you!

• "But those events are both independent and mutually exclusive" is technically incorrect, and the displayed formula below that uses new undefined names. That part of the answer should be omitted. (If $A$ and $B$ mean what I think they mean, the formula for $\Pr(A\cup B)$ is not right.) The final formula is correct. Commented Jan 25, 2016 at 20:17
• $A_1$ and $B_1$ are independent. They are not mutually exclusive. In all but trivial cases, independent and mutually exclusive are incompatible. If $C$ and $D$ are independent, knowing that $C$ occurred tells us nothing about $D$. If they are mutually exclusive, knowing that $C$ occurred tells us $D$ did not. Commented Jan 25, 2016 at 20:31
• The three events "both red", "both white", and "both green" are mutually exclusive. That justifies the final addition. Commented Jan 25, 2016 at 20:39
• @Mitscaype: Faster than just multiplying three pairs of fractions and adding? How could computing a hypergeometric distribution be faster than that? Commented Jan 25, 2016 at 20:52
• Faster would be to leave out the formulas. It should be clear that the answer is probability of red red plus probability of white white plus $\dots$. Commented Jan 25, 2016 at 20:59

Comment: From your final formula, approved by @AndreNicholas, I get a probability of 0.3449.

In the following simulation in R of a million such experiments, I used numbers 1, 2, and 3, for the three respective colors. Results are as follows:

 box.a = c(rep(1,3),rep(2,8),rep(3,13))
box.b = c(rep(1,5),rep(2,7),rep(3,6))
m = 10^6
a =sample(box.a, m, repl=T)  # vector of draws from Box A
b =sample(box.b, m, repl=T)  # vector of draws from Box B
mean(a==b)                   # proportion of matches
## 0.344875


Agreement to about three places is within the margin of simulation error. So your formula does indeed seem to work. You should make sure you resolve the difficulties in the derivation of your formula. I'm not sure there is a simpler formula or a basically simpler way to get the formula.

• Yeap, I also think that that's it. I was just curious first of all to see if I was right about the original formula and secondly, to check if anyone has any better solution. And by better, perhaps a faster one. Seems like there is not. Nevertheless thank you for taking time to verify it. :) Commented Jan 25, 2016 at 22:27
• Glad it's settled. Elementary, but interesting question. Commented Jan 25, 2016 at 22:53