Skip to main content

Generate arbitrary number of digits of Pi using a streaming algorithm.

Project description

PiDigits Implements the ‘Unbounded Spigot Algorithm for the Digits of Pi’ by Jeremy Gibbons. The paper describing this algorithm can be found at the following URL: http://www.cs.ox.ac.uk/jeremy.gibbons/publications/spigot.pdf

Installation

pidigits is avalaible through Python Package Index (PyPI) using pip.

>>> pip install --upgrade pidigits

To uninstall using pip.

>>> pip uninstall pidigits

Usage

PiDigits provides a generator function named piGenerator that yields the digits of Pi as needed.

>>> from pidigits import piGenerator
>>> mypi = piGenerator()
>>> first20pi = [mypi.next() for i in range(20)]
>>> first20pi
[3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 8, 9, 7, 9, 3, 2, 3, 8, 4]

Example: Verify the Feynman point.

>>> mypi = piGenerator()
>>> first1001 = [mypi.next() for i in range(1001)]
>>> feynman = first1001[762:768]
>>> print feynman
[9, 9, 9, 9, 9, 9]

Alternatively you can also use the getPi(n) function to get the first n digits of Pi.

>>> from pidigits import getPi
>>> first20pi = getPi(20)
>>> first20pi
[3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 8, 9, 7, 9, 3, 2, 3, 8, 4]

License

pidigits is licensed under Apache License 2.0.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

pidigits-0.3.zip (11.8 kB view hashes)

Uploaded Source

pidigits-0.1.zip (11.2 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page