In earlier probability lessons, we explored discrete events like flipping coins and rolling dice. But what happens when the choices are continuous points along a line? This is known as geometric probability.
In the 1972 MAA High School Mathematics Contest (Problem #17), contestants were presented with this problem:
A piece of string of length 1 is cut in two at a point selected completely at random. What is the probability that the longer piece is at least 3 times the length of the shorter piece?
Let the cut point be $x$ chosen uniformly between $0$ and $1$.
The two resulting pieces have lengths $x$ and $1 - x$.
The longer piece has length $\max(x, 1 - x)$.
The shorter piece has length $\min(x, 1 - x)$.
We want the ratio of the longer piece to the shorter piece to be at least 3:
$$\frac{\text{longer}}{\text{shorter}} \ge 3$$
We can use a Monte Carlo simulation in Lua by generating thousands of random cuts with math.random(), calculating the piece ratios, and estimating the exact probability!
cut = math.random() longer = math.max(cut, 1 - cut) shorter = math.min(cut, 1 - cut) if longer / shorter >= 3 then favorable = favorable + 1 end
Move the mouse over a dotted box for more information.
Theoretically, if the cut occurs at $x \le 0.5$, then $1 - x \ge 3x \implies 4x \le 1 \implies x \le 0.25$. By symmetry, cuts at $x \ge 0.75$ also qualify. Together, the qualifying intervals $[0, 0.25]$ and $[0.75, 1.0]$ have a combined length of $0.25 + 0.25 = 0.50$, or exactly a $50\%$ probability!
Now you try.
Replace ???? with longer / shorter >= 3 and favorable / trials. Run the simulation and see how close your simulated probability gets to $0.50$!
Type your code here:
See your results here:
This code has ???? inside the if condition and in the probability calculation. Check if longer / shorter >= 3, and compute prob = favorable / trials!
Share your code
Show a friend, family member, or teacher what you've done!