Giter VIP home page Giter VIP logo

akjroller / collatz-conjecture-explorer Goto Github PK

View Code? Open in Web Editor NEW
2.0 1.0 0.0 12 KB

A computational service and API for exploring and understanding the Collatz Conjecture. Continuously calculates Collatz sequences from any given number and stores results in a SQLite database for querying and analysis.

License: MIT License

Python 100.00%
collatz collatz-algorithm collatz-conjecture collatz-conjecture-visualizer collatz-problem mathematics number-theory restful-api collatz-api

collatz-conjecture-explorer's Introduction

Collatz Conjecture Explorer

This repository contains an API and a computation service for exploring and understanding the Collatz Conjecture, an unsolved problem in mathematics.

Features

The Collatz Conjecture Explorer offers several features:

  • Continual calculation of Collatz sequences starting from any given number, and storage of these results in a SQLite database.
  • A RESTful API for querying the results of these calculations, including specific sequences, statistical summaries, and more.
  • Ability to query Collatz sequences for a specific range of numbers or search sequences by specific criteria.
  • Ability to retrieve the top N sequences with the highest number of steps, as well as average statistics over a specified number of sequences.
  • The computation service automatically updates distribution statistics when it's shut down.

Requirements

  • Python 3.7 or newer
  • SQLite3
  • FastAPI
  • Uvicorn (for serving the API)

Installation

First, clone this repository using git:

git clone https://github.com/akjroller/collatz_conjecture_explorer.git
cd collatz_conjecture_explorer

Then install the dependencies using pip:

pip install -r requirements.txt

Usage

To start the computation service, run:

python collatz.py

The computation service will continually calculate Collatz sequences and store the results in a SQLite database.

To start the API, run:

uvicorn app:app --host 0.0.0.0 --port 8000

You can then access the API at http://localhost:8000. For example, to get the Collatz sequence for the number 6, you would access http://localhost:8000/collatz/6.

API Endpoints

Here are some of the API endpoints you can use:

  • /collatz/{num}: Get the Collatz sequence and its statistics for a specific starting number.
  • /stats: Get the overall computation statistics, including the last checked number, total computation time, and average steps.
  • /collatz/range/{start}/{end}: Get the Collatz sequences for a range of starting numbers.
  • /collatz/top/{n}: Get the top N Collatz sequences with the highest number of steps.
  • /collatz/average/{n}: Get the average number of steps and average max value over the last N Collatz sequences.
  • /collatz/search/{number_of_steps}/{max_value}: Search for Collatz sequences by a specific number of steps and max value.
  • /collatz/stats/hourly: Get the hourly Collatz computation statistics.
  • /collatz/stats/distribution: Get the distribution statistics for Collatz computations. (Not yet implemented)

Notes

The computation service can be interrupted with CTRL+C or by closing your CLI , at which point it will calculate and store distribution statistics.

The API includes a middleware for blocking requests from specific IPs. The list of blocked IPs can be updated by adding them to blocked_ips.txt and using the /refresh_block_list/{password} endpoint with the correct password.

Contributing

Contributions are welcome! Please create an issue to discuss the changes or open a pull request.

License

This project is licensed under the terms of the MIT license.

Contact

If you have any questions, you can contact the author at [email protected].

collatz-conjecture-explorer's People

Contributors

akjroller avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.