Skip to content

Ian729/pi-digit-counter

Repository files navigation

π Digit Counter & Visualizer

A Python script and interactive web visualization that moves a pointer through the digits of π (pi) and counts the occurrence of each digit (0-9) as it progresses.

🌐 Web Version (Live Demo)

The interactive web version is available at: GitHub Pages

Features:

  • 🎬 Animated pointer moving through π digits
  • 📊 Real-time digit counting (0-9)
  • 📈 Visual progress bars and statistics
  • ⚡ Adjustable animation speed
  • 🎨 Beautiful, modern UI

Running Locally

Simply open index.html in your web browser, or use a local server:

# Python 3
python -m http.server 8000

# Node.js
npx http-server

# Then open http://localhost:8000 in your browser

🐍 Python Version

A command-line Python script for calculating and analyzing π digits.

Features

  • Calculates π digits up to a specified precision
  • Moves a pointer through π digits step by step
  • Counts occurrences of each digit (0-9) in real-time
  • Displays statistics including counts and percentages
  • Visual bar charts for digit distribution
  • Interactive mode for step-by-step exploration

Requirements

  • Python 3.6+
  • Standard library only (decimal, collections)

Optional (for better performance with large precisions):

  • mpmath - For faster π calculation
pip install mpmath

Usage

Interactive Mode

Run the script and follow the prompts:

python pi_digit_counter.py

You'll be prompted to:

  1. Enter the number of decimal places to calculate
  2. Move the pointer forward by entering steps
  3. Type 'auto' to process all remaining digits
  4. Type 'quit' to exit

Programmatic Usage

from pi_digit_counter import PiDigitCounter

# Create a counter with 1000 decimal places
counter = PiDigitCounter(precision=1000)

# Move pointer forward by N steps
counter.move_pointer(100)

# Display current status
counter.display_status()

# Get current digit counts
counts = counter.get_counts()

# Get percentages
percentages = counter.get_percentages()

See example_usage.py for more examples.

📁 Project Structure

pi_visualizer/
├── index.html          # Web app HTML
├── styles.css          # Web app styles
├── script.js           # Web app JavaScript
├── pi_digit_counter.py # Python script
├── example_usage.py    # Python examples
├── requirements.txt    # Python dependencies
└── README.md          # This file

🚀 Deployment

This project is set up to automatically deploy to GitHub Pages using GitHub Actions.

Manual Setup

  1. Go to your repository Settings → Pages
  2. Set source to "GitHub Actions"
  3. The workflow will automatically deploy on pushes to main or master branch

Local Development

For local development, just open index.html in your browser or use a local server.

🧮 How It Works

  1. Initialization: Calculates or loads π digits
  2. Pointer: Starts at position 0 (the digit '3')
  3. Movement: As the pointer moves forward, it reads each digit
  4. Counting: Each digit encountered increments its counter
  5. Statistics: Real-time display shows counts, percentages, and visual bars

📝 Notes

  • The pointer starts at the digit '3' (position 0)
  • Decimal places start from position 1 onwards
  • For very large precisions (>10000), consider using mpmath for faster calculation
  • The Python script uses Machin's formula for π calculation (fallback) or mpmath if available

📄 License

Free to use and modify.

About

π Digit Counter & Visualizer

Resources

Stars

Watchers

Forks

Contributors