Skip to main content

Probability Riddle Using Python: Balls of Two Colors

 Riddle:

A box contains p white balls and q black balls, and beside the box lies a large pile of black balls. Two balls are drawn at random (with equal likelihood) out of the box. If they are of the same color, a black ball from the pile is put into the box; otherwise, the white ball is put back into the box. The procedure is repeated until the last two balls are removed from the box and one last ball is put in. What is the probability that this last ball is white? 


Python Solution (I got it half right at first):

At first I assumed 2 even numbers without thinking that if any of the numbers was odd it would make a difference:


Then upon making the white balls odd, the solution changed, hence the complete solution is the screenshot up and the one down combined:


Riddle source:

Problem 1 in https://mathematicalolympiads.files.wordpress.com/2012/08/from-erdos-to-kiev-problems-of-olympiad-caliber-ross-honsberger.pdf