Pi Day sneaked up on me a bit this year, just as pi likes to sneak into the solutions to all sorts of maths problems. This year’s method of approximating pi exemplifies this, as explained by 3Blue1Brown in his excellent video about it.

The Theory

I recommend watching the video linked above for a proper explanation of both the problem and the solution, but here’s a summary:

In a world of perfect 1 dimensional physics (no friction etc.), given a wall, a stationary block and a second block moving towards it, there will be a number of collisions, exchanging energy and momentum between the blocks before they end up moving apart, never to meet again. If the second block has a mass that is a 100d-1 times that of the smaller block, the number of collisions will be the first d digits of pi.

For example, if both blocks are 1kg, they will collide 3 times. If one is 1kg and the other is 100kg, they will collide 31 times. 10,000kg gives 314 collisions, and 10,000,000,000kg gives 314159.

The Simulation

Below is a simulation of this process. It initialises the scene based on the mass provided and repeatedly calculates the time of the next collision and the state of the blocks immediately afterwards. By counting these collisions until it’s determined that there are no more, we get a (very slow) estimate of pi.

Beyond a mass of about 1,000,000, the page may start to freeze while simulating. The most I’ve managed to calculate is 3141592, but feel free to push it beyond this and find the bugs and inaccuracies that emerge.




Number of collisions: -