Home > python > Digits of PI (Part 1)

Digits of PI (Part 1)

Problem
You want to work with the digits of PI. Why? For instance you want a new job (screenshot here if it got removed since then).

Solution
I like simple solutions. So instead of generating the digits, I simply fetched the data from the web. This is a fast, efficient, and painless approach of the problem :) Visit http://newton.ex.ac.uk/research/qsystems/collabs/pi/, where you can download several data files.

For the lazy pigs
I made a script that downloads the data, parses them, and returns the digits as a string. Here it is.

Usage (get the first 30 digits of PI after the dot):

#!/usr/bin/env python

from jabbapylib.math import pi

def main():
    digits = pi.get_digits_of(pi.PI3)    # get 10^3 = 1000 digits
    print digits[:30]

if __name__ == "__main__":
    main()

Output:

141592653589793238462643383279

jabbapylib is here

About these ads
Categories: python Tags: ,
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 76 other followers

%d bloggers like this: