Sunday Times Teaser 2594 – Just Enough
by Andrew Skidmore
Published: 10 June 2012 (link)
I have two identical bags of balls, each containing two reds, two yellows and two blues. Blindfolded throughout, I remove just enough balls from the first to be sure that the removed balls include at least two colours. I place these balls in the second bag. Then I remove some balls from the second bag and put them in the first: I move just enough to be sure that the first bag will now contain at least one ball of each colour.
What (as a percentage) is the probability that all the balls left in the second bag are the same colour?
One Comment
Leave one →
-
Brian Gladman permalink12345678910111213141516171819202122232425262728293031323334353637from itertools import permutations# the three ball coloursyellow, blue, red = 1, 2, 3# the initial bag contentsbag = ( yellow, blue, red, yellow, blue, red )count_all = count_same = 0# we need three balls from the first bag to# ensure that we have at least two coloursfor p in permutations(bag, 3):# the possibilities for bag one and two are now:## 1 2# ybr yyybbbrrr# yyr yybbbbrrr# yyb yybbbrrrr# rry yyybbbbrr# rrb yyyybbbrr# bby yyybbrrrr# bbr yyyybbrrr## to be sure that bag 1 has at least one ball# of each colour we have to transfer at least# six balls back from bag two to bag one, which# leaves three balls in bag twofor q in permutations(bag + p, 3):# count the permutations that leave all balls# in bag two of the same colourif q[0] == q[1] == q[2]:count_same += 1# count all permutationscount_all += 1fs = 'There is a {} percent probability.'print(fs.format(100 * count_same / count_all))