https://github.com/fistgang/primespark
Prime Number Generator using PySpark
https://github.com/fistgang/primespark
prime-numbers pyspark sieve-of-atkin sieve-of-eratosthenes spark
Last synced: about 2 months ago
JSON representation
Prime Number Generator using PySpark
- Host: GitHub
- URL: https://github.com/fistgang/primespark
- Owner: FistGang
- License: mit
- Created: 2024-06-12T12:39:10.000Z (11 months ago)
- Default Branch: master
- Last Pushed: 2024-06-29T13:47:46.000Z (10 months ago)
- Last Synced: 2025-03-06T17:15:42.995Z (about 2 months ago)
- Topics: prime-numbers, pyspark, sieve-of-atkin, sieve-of-eratosthenes, spark
- Language: Python
- Homepage:
- Size: 15.1 MB
- Stars: 0
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## Prime Number Generator using PySpark
This project is a Prime Number Generator that uses PySpark to calculate prime numbers within a given range or to find the nth prime number within a specified range. The program uses sieves algorithm to generate prime numbers up to a specified limit and then filters the prime numbers within the desired range. The results are saved to an output directory specified by the user.
## Prerequisites
Before running this project, ensure you have the following installed:
- Python 3.9+
- Apache Spark
- PySpark## Usage
## Installations
You need to install dependencies to run the project that specified in the `requirements.txt` as follow:
```bash
# Create virtual environment
python3 -m venv .venv
# Activate environment
source .venv/bin/activate
# Install deps
python3 -m pip install -r requirements.txt
```### Running the Script
The script supports two modes of operation: generating primes within a range and finding the nth prime within a range.
#### Generating Primes in a Range
To generate prime numbers within a specified range, use the following command:
```bash
python3 prime_generator.py --method range --start --end --output_dir --num_slices --sieve
```
For example, to find prime numbers between 10 and 100 using the Sieve of Eratosthenes and save the results to the `primes` directory:```bash
python3 prime_generator.py --method range --start 10 --end 100 --numslice 16 --output_dir primes --sieve eratosthenes
```To use the Sieve of Atkin:
```bash
python3 prime_generator.py --method range --start 10 --end 100 --numslice 16 --output_dir primes --sieve atkin
```#### Finding the nth Prime in a Range
To find the nth prime number within a specified range, use the following command:
```bash
python3 prime_generator.py --method nth --start --end --output_dir --num_slices --sieve
```For example, to find the 5th prime number between 10 and 100 using the Sieve of Eratosthenes and save the result to the `primes` directory:
```bash
python3 prime_generator.py --method nth --start 10 --end 100 --nth 5 --numslice 16 --output_dir primes --sieve eratosthenes
```To use the Sieve of Atkin:
```bash
python3 prime_generator.py --method nth --start 10 --end 100 --nth 5 --numslice 16 --output_dir primes --sieve atkin
```## License
This project is licensed under the MIT License. See the `LICENSE` file for more details.
## Contributing
Contributions are welcome! Please fork the repository and submit a pull request for any improvements or bug fixes.