It's as ill posed as the Monty Hall problem. The issue is in what it means for the first ball to picked randomly. Would the question be valid if the first ball was green? If not, then it's equivalent to the standard answer to the Monty Hall problem. Analyze it as if the first ball was not picked randomly (i.e. Monty intentionally picked the wrong door).
I'm not sure why you think it is ill posed. The question is, you randomly pick a ball, IF it is red then... So yeah, it is basically the same as "someone else removes a red ball" now randomly select a ball. OR Pick a ball, is the color of the second ball more likely to be the same as the first, different, or equal. That is really the question here. edit: After thinking about it some more, it is NOTHING like handing t…
When in doubt, simulate (with code). Do this N times for a large N, and take the ratio to get a probability estimate.
So the question is: How will you code it? You'll find half the people code it one way (to get one answer), and the other half will code it differently to get a different answer. That's because it is ill posed.
As an example, I would code it as:
Let n be a random number from 1 to 100 (cannot be 0!)
We throw away one red ball as we know we picked one.
Construct a list of n-1 red balls, and 100 - n green balls.
Pick a ball at random. Success if it is red.
Repeat this N times where N is large.
Take the ratio of successes with N.
When I run it, I get 50%
How would you simulate it differently?
The problems with the code in the submission:
If n==0, he continues, but still counts it as a trial (he still divides by num_trials). He should deduct the number of trials every time n==0.