Skip to content

A Python implementation of an infinite spigot algorithm to compute and stream the digits of π (pi) in real-time. This project is designed for educational purposes to demonstrate how π can be calculated and output digit-by-digit using an efficient iterative approach.

License

Notifications You must be signed in to change notification settings

TianmuTNT/PiDigits

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 

Repository files navigation

PiDigits

License: MIT

A Python program that streams the digits of π (pi) indefinitely, calculated digit-by-digit using Jeremy Gibbons' infinite spigot algorithm.

Features

  • Real-time digit-by-digit computation of π.
  • Minimal memory usage (no precomputed values stored).
  • Clean, generator-based implementation for seamless integration into other projects.

Usage

Prerequisites

  • Python 3.x

Running the Program

  1. Clone the repository:
    git clone https://github.com/TianmuTNT/PiDigits.git  
    cd PiDigits  
  2. Run the script:
    python3 pi_digits.py  
  3. The program will print 3. followed by the decimal digits of π, one by one.
  4. Press Ctrl+C to stop execution.

Algorithm Details

This implementation uses the infinite spigot algorithm by Jeremy Gibbons. Unlike finite spigot methods, it avoids preallocating memory for all digits and generates them on-the-fly.

License

This project is licensed under the MIT License. See LICENSE for details.

Disclaimer

For Educational Purposes Only
This code is intended to demonstrate algorithmic concepts and is not optimized for high-performance π computation.

Contributing

Feel free to open issues or submit pull requests for improvements.

Star History Chart

About

A Python implementation of an infinite spigot algorithm to compute and stream the digits of π (pi) in real-time. This project is designed for educational purposes to demonstrate how π can be calculated and output digit-by-digit using an efficient iterative approach.

Topics

Resources

License

Stars

Watchers

Forks

Languages