For Buffon's needle problem, Laplace considered a grid with horizontal and vertical lines one unit apart. He showed that the probability that a needle of length L≤1 crosses at least one line is
p=π4L−L2.
To simulate this experiment we choose at random an angle θ between 0 and π/2 and independently two numbers d1 and d2 between 0 and L/2. (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 d1≤(L/2)sinθ or d2≤(L/2)cosθ. We do this a large number of times and estimate π as
πˉ=a4L−L2,
where a is the proportion of times that the needle crosses at least one line. Write a program to estimate π by this method, run your program for 100, 1000, and 10,000 experiments, and compare your results with Buffon's method described in Exercise 6. (Take L=1.)