The Problem
You have two jars, 50 red marbles and 50 blue marbles. A jar will be picked at random, and then a marble will be picked from the jar. Placing all of the marbles in the jars, how can you maximize the chances of a red marble being picked? What are the exact odds of getting a red marble using your scheme?
The Solution
Fill the bottom half of each jar with blue marbles. Then fill the top half of each jar with red marbles. You then have a 100% chance of picking a red marble.
I've got a masters degree in computer science and over 10 years of experience building web-based systems using Java/J2EE, Ruby, Rails and PHP. I'm a strong believer in the effectiveness of Agile Methods.
One Comment
This solution assumes that once a jar is chosen at random, a marble is chosen in a nonrandom fashion. I disagree with this solution because I think that, judging from the context of the problem (we’re asked to compute “exact odds”), we should assume that selection of the marble from the chosen jar is random as well.
In that case, you should put 1 red marble and 0 blue marbles in the first jar, and you should put 49 red marbles and 50 blue marbles in the second jar.
.50 + .50*(49/99) = .7474747474
There is a 74.747474% chance that a red marble will be picked.