The Least Efficient Way to Calculate Pi

TL;DR: Try out the interactive code at the bottom. You're throwing needles of length 1 onto a grid of lines that are also a unit apart. The probability that a needle touches a line is 2/pi. Using this, we can (very poorly) approximate pi.

Aside from every whole number under 10, the most well-known mathematical constant is probably pi. Pi is exactly the circumference of a perfect circle divided by its diameter, which already makes it interesting in its own right. But pi is used for so much more than calculating areas or circumferences of circles. Wherever a hidden circle finds its home in an area of math, pi is certain to appear.

The topic of a hidden circle takes us to the worst way to calculate pi. What makes this method so bad is that you're not guaranteed to get the right answer; everything is left to chance, and our approach will only ever give us an approximation. But the nature of uncertainty implies that we cannot demand our approximations be within a certain range of correct!

For the mathematicians reading, yes, we're talking about Buffon's needle problem. The setup goes like this: you're presented with a grid of horizontal lines, each with a distance of 1 between them. You throw a needle, also of length 1, randomly onto this grid. The probability that any individual toss will touch one of the gridlines is exactly 2/pi.

So, why is pi showing up here?? We have straight lines, and last I checked, needles are also straight. So there's nothing curved about this whole setup, right? How could circles possibly come into play?

Well, let's start by assuming we know where the tip of the needle lands. Super unlikely, I know, but we're just on the hunt for a circle. Once we know where the tip lands, let's pin that down. Now, we don't know the angle that the needle lands at, so we can start to sweep it around and see for which angles it'll actually cross one of the gridlines.

But if we're sweeping the needle around with one of the tips fixed, we're just tracing out a circle! And in fact, this is exactly the circle we're after. For each place the tip could be, we trace out a circle with the other tip of the needle. Then, we calculate which portion of that circle will actually touch one of the gridlines.

And if we want to arrive at that super precise answer of 2/pi, we can use some techniques from calculus to help us out (or, there's a geometric proof due to Joseph-Émile Barbier and published in the 2nd edition of Proofs from the Book). Either way, pi finds its esoteric way into this puzzle and gives us a horribly inefficient way to calculate it.

Every formula used to calculate pi nowadays is incredibly sophisticated, with only a handful of computations needed to generate several correct digits with certainty. Buffon's needle problem is horrible. You can toss thousands upon thousands of needles (which is already slow), and you still might not even have 2 correct digits.

Don't believe me? Give it a try below! I wrote this code in Mathematica, and while there's other flashier simulations of Buffon's needle problem, I had fun working out some of the technicalities in the code. It's still a bit shaky, though, so be a little patient please :-)

And HAPPY PI DAY!!





And a gif I generated from an earlier iteration of the code: