Skip to content
Generate pi in a ridiculous way using elastic collisions
Branch: master
Clone or download
jakevossen5 Merge pull request #4 from nivkner/final_countdown
count the collisions with the wall at the end
Latest commit ff42e21 Feb 22, 2019
Type Name Latest commit message Commit time
Failed to load latest commit information.
.gitignore Added cargo build and increase opt-code Jan 20, 2019
Cargo.toml Added cargo build and increase opt-code Jan 20, 2019
LICENSE Initial commit Jan 18, 2019 Fixed link Jan 20, 2019
demo1.gif moved to demo1 because it wasn't changing Jan 20, 2019
diff.png Added alg analysis and example. Jan 20, 2019 count the collisions with the wall at the end Feb 22, 2019



This is a way to generate digits of pi by using elastic collisions between an object 100^N larger than the other with a wall and counting the number of collisions.

Inspired by this video by 3Blue1Brown, technical paper.


This program is written in Rust, primarily for speed. First, clone the repository using git clone or by downloading and extracting the zip.

Then, install Rust from the offical rust guide.

Compile the program using RUSTFLAGS="-C target-cpu=native" cargo build --release. Then you can run the program using the executable found in the target/release/ folder. By default, it will start with 1 digit, then 2, then 3, etc, until you cancel the program. You can modify the starting value by change n in the source and recompiling.


I found that 9 is about the limit a modern computer can calculate in a reasonable time (about 10 seconds on my 2018 Macbook Pro, and similar speeds on other computers). It gets very hard to calculate numbers above 10.

Also, the weight of the small block is the smallest possible floating point number. This is to try to prevent oveflow, which will happen if you start with a small block of mass 1. Eventually there is going to be an overflow somewhere because the numbers are so big, but it would take hours to generate that number anyway.

Each increase in n will take almost exactly 10 times longer to complete than the previous n, making this approxemently a O(10^N) algorithm. For example:


You can’t perform that action at this time.