The YouTube channel 3Blue1Brown recently uploaded a video where they give the following situation: we have two sliding blocks and a wall on the left. The first block starts out motionless, and the second block comes in sliding from the right.

The second block hits the first one, transferring some of its momentum to the first. The second slides to the wall, where it reflects, hitting the second block again. We disregard any form of friction since that’s no fun in thought experiments.

Depending on the relative masses of the two blocks, there will be some number of collisions after which both blocks are flying off to infinitely far to the right, and we can count the number of collisions that will happen.

It turns out, that if the second block is 100n times heavier than the first block, the number of collisions is the first n + 1 digits of pi. Why this works is shown in a follow-up video. I’m no mathematician, but I do want to play with it a little.

Below I have a demo where you can select the relative weight of the second block as a factor of the first one. Choose your weight, click start, and watch the blocks bounce!

Note from the implementation: this demo is designed to run at 60 frames per second. However, almost all of the collisions happen well within 1/60th of a second, so you will see a sudden jump in the number of collisions.

Second note: I have successfully tested the demo up up to 10010. However, since nearly all the collisions happen at the same time, and we need to count them all, simulation time will slow down when that happens. You can still see the collisions count up.