Algorithm Arena
Monte Carlo Estimator
Estimate pi by throwing random points at a circle, watch the error shrink with sample size, and internalize why halving the error always costs four times the samples.
How it works
The game estimates pi with the classic circle-in-square method: sample points uniformly in the unit square, count how many land inside the quarter circle (x squared plus y squared at most 1), and multiply the inside fraction by 4, since P(inside) = pi/4. You choose the sample count with a slider over five options - 100, 500, 2,000, 10,000, or 50,000 - and press Run simulation.
Each run displays the points-inside count, the estimate, true pi for comparison, and the standard error of the estimator at your chosen N. A history strip keeps the last several runs as N-and-estimate chips, so you can watch the estimates tighten around pi as N grows and scatter at small N.
After a run, the game asks one prediction question: standard error scales like 1 over root N - how many times more samples would cut this run's SE in half? Type a multiplier and press Check; the game reveals whether you matched the true answer and shows the concrete sample counts for your run.
How scoring works
There is no cumulative score. The single graded interaction is the halving question, marked correct only if your typed multiplier equals 4 - the exact consequence of SE proportional to 1 over root N, regardless of the current N.
The standard error shown is computed, not asserted: for the pi estimator the per-sample indicator has variance p(1-p) with p = pi/4, so SE = sqrt(p(1-p)) / sqrt(N).
The reveal spells out the arithmetic for your actual run - for example, going from 10,000 to 40,000 samples roughly halves that run's error.
The square-root law is the entire lesson
Monte Carlo error does not shrink linearly with effort. The estimator is an average of N independent draws, its variance is the per-draw variance divided by N, and its standard error is therefore proportional to 1 over root N. Halve the error and you must double root N, which means quadrupling N. Ten times less error costs one hundred times the samples. This one relationship governs every Monte Carlo system you will ever run, from option pricers to risk engines.
Use the slider to feel it: the jump from 100 to 10,000 samples is a factor of 100 in work but only a factor of 10 in precision. Run 100 samples a few times and watch estimates like 3.28 and 3.04 bounce around; at 50,000 they cluster near 3.14. The history chips make the convergence - and its slowness - visible in a way the formula alone never does.
Read the standard error as an error bar, not a bound
The SE readout tells you the typical size of the miss, not a guarantee. Roughly two-thirds of runs land within one SE of pi and about 95 percent within two - so a run that misses by 1.5 SE is unremarkable, and expecting the estimate to match pi to the digits the SE cannot support is the classic misread. At N = 2,000 the SE is about 0.009, so digits beyond the second decimal place of a single run are noise.
This is also the interview-grade habit: whenever you quote a simulated number, quote its SE alongside it. A candidate who says my Monte Carlo price is 4.21 plus or minus 0.03 has demonstrated more understanding than one who quotes 4.2137 with no error bar - the extra digits are a claim the simulation cannot back.
Know why this particular estimator has the variance it does
Each sample is a Bernoulli indicator - inside or not - with success probability p = pi/4, about 0.785. A Bernoulli variable has variance p(1-p), about 0.169, so the per-sample standard deviation s is about 0.41, and the estimate 4 times the mean scales that up by 4. Being able to derive s rather than treat it as a given is what turns how many paths do I need from a guess into arithmetic: target SE, then N = (s / SE) squared.
The same recipe generalizes: for any Monte Carlo estimate, find (or estimate from a pilot run) the per-sample standard deviation, and the sample count for a target precision follows immediately. Variance-reduction techniques you may meet later - antithetic variates, control variates - are all attacks on s, because attacking N is a losing battle at 4x per halving.
A worked example
Set the slider to 2,000 and run. Suppose 1,573 of 2,000 points land inside: the estimate is 4 times 1573/2000 = 3.14600, against true pi 3.14159. The standard error shown is sqrt(p(1-p)) / sqrt(2000) with p = pi/4, which is about 0.41 / 44.7, roughly 0.0092.
The miss is 3.14600 minus 3.14159 = 0.00441, about half a standard error - a completely typical outcome, not a lucky one. The digits 3.14 are trustworthy; the 6 in the third decimal place is noise.
Now the halving question: how many times more samples to cut the 0.0092 SE to 0.0046? SE is proportional to 1 over root N, so the answer is 4 - going from 2,000 to 8,000 samples. Answering 2, the intuitive linear guess, is exactly the error the question exists to burn off. To get one more decimal digit of pi - a 10x smaller SE - you would need 100x the samples, 200,000.
Common mistakes
• Answering 2 to the halving question. Error scales with root N, not N - halving error always quadruples the sample bill.
• Reading more digits off a single run than the SE supports. At small N the third decimal place is pure noise.
• Treating one close estimate at low N as evidence the estimator is accurate there. Run 100 samples repeatedly and the scatter tells the real story.
• Thinking the halving multiplier depends on the current N. It is always 4, at every N - that is what a power law means.
• Quoting Monte Carlo results without an error bar. The SE is computed for you here; in real work you must compute it yourself, and interviewers check.
Why interviews test this
How many more paths do you need to halve the error is a genuine, frequently asked quant interview question, and the answer - four times - is a one-liner that instantly signals whether a candidate understands the 1 over root N law. Monte Carlo is the workhorse for derivative pricing, risk simulation, and backtesting, so its cost structure is core professional knowledge.
The deeper skill being screened is the habit of attaching uncertainty to every estimated number. Candidates who reflexively pair estimates with standard errors read as people who will not ship a number their simulation cannot defend.