3 ms·
Forgive my frequentist bent, but: 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
by BeetleB 3y ago
Forgive my frequentist bent, but:
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.
- bagels 3y agoThe revised code here gets to correct estimate: https://news.ycombinator.com/item?id=39198581 https://news.ycombinator.com/item?id=39198581 Roughly similar to what I wrote too.