Exercise
For Buffon's needle problem, Laplace[Notes 1] considered a grid with horizontal and vertical lines one unit apart. He
showed that the probability that a needle of length [math]L \leq 1[/math] crosses at least one line is
To simulate this experiment we choose at random an angle [math]\theta[/math] between 0 and [math]\pi/2[/math] and independently two numbers [math]d_1[/math] and [math]d_2[/math] between 0 and [math]L/2[/math]. (The two numbers represent the distance from the center of the needle to the nearest horizontal and vertical line.) The needle crosses a line if either [math]d_1 \leq (L/2)\sin\theta[/math] or [math]d_2 \leq (L/2)\cos\theta[/math]. We do this a large number of times and estimate [math]\pi[/math] as
where [math]a[/math] is the proportion of times that the needle crosses at least one line. Write a program to estimate [math]\pi[/math] by this method, run your program for 100, 1000, and 10,00 experiments, and compare your results with Buffon's method described in Exercise Exercise. (Take [math]L = 1[/math].)
Notes