Inspiration/What it does

Takes a user-inputted number n and calculates Pi to the nth digit. You'll be asked to enter an integer value until the program detects that you've inputted an integer (e.g. "hi" won't be accepted).

How I built it

I implemented the Nilakantha Series in Python, using the latter's built-in math and Decimal modules. The series is iterated 15000 times — despite the staggering number, the script is unfortunately only accurate up to 13 digits and takes around two minutes (?) to run. And no, I couldn't resist naming my Python file pi.py :)

Challenges I ran into/What I learned

Deciding between the tradeoff of runtime vs. accuracy (and also how much my CPU could actually handle :/). It was either loop the calculation so many times that it'd take several minutes to return a value, or repeat it less but sacrifice precision... And, of course, hoping my computer wouldn't crash or that its fan wouldn't give out (oops).

I read about several ways to calculate Pi, and even though this script is far from the best (or even an efficient solution), I'm glad to have learned about the Nilakantha Series, as well as more about Pi.

What's next for Pi with Nilakantha

There's definitely lots of improvement for this program:

  • Improving the runtime of the script (using the Nilakantha Series takes a very long time/lots of iterations if you want accuracy): using another calculation method that's more accurate with less iterations
  • Implementing a version in JavaScript to live demo on my LHD: Build microsite (or connecting this Python script somehow)

Built With

Share this project:

Updates