An Unconventional Estimation

Vibhu Dalal | K3

The most intriguing and inviting problems in maths or related domains are often those which are simple to understand but appear nearly impossible to solve, and yet possess a straightforward, elegant solution. Such problems tend to surprise their readers at first, giving them the false impression that they surely lack the key ingredients required to solve the problem. Attempting to solve such problems may appear akin to trying to pull a rabbit out of the hat, whereas in reality, all that’s needed is one creative insight. Such is the nature of the following problem.

Problem

Given a function which outputs a random number between 0 and 1, describe a method to estimate pi.

Solution

First, note that the random function can be called twice to get a random point (x,y), which belongs to the 1x1 square as shown below:

Follow this procedure to get a large number of random points:

The key insight into the problem lies in the following figure.

We can now work with the following approximation:

# points in the quarter-circle# total points area of the quarter-circlearea of the square=π(1)2412=π4

Thus:

π4 · # points in the quarter-circle# total points

The remaining task is to determine whether a generated point lies inside the quarter-circle. Since the quarter-circle’s radius is 1, the generated point will belong to it if the distance between the point and the origin is less than 1. In other words, a generated point (x,y) must satisfy the following condition to belong to the quarter-circle:

x2+y2< 1

In summary, the method for approximating the value of pi given a function which outputs a random number between 0 and 1 is:

  1. Generate a large number of random points (x,y) while keeping track of the number of points which fall inside the quarter-circle.
  2. Use equation (1).

Note of course that the larger the quantity of the generated points, the better the approximation of pi.