## bin+lib rprime

Provides useful functions for prime numbers

### 2 releases(1 stable)

 1.0.0 Mar 1, 2022 Mar 1, 2022

#1254 in Math

7KB
69 lines

# RPRIME

Fun with prime numbers in Rust.

Since I've been digging into prime numbers a lot lately, I was wondering how to write a tool that lets you check whether a number is a prime number. `rprime` is that tool.

## Building

You will need the following tools installed and available:

• Rust
• Git

To compile `rprime`, follow these steps:

• 1.) Get the source code:
``````\$ git clone https://github.com/iamtheblackunicorn/rprime.git
``````
• 2.) Change directory:
``````\$ cd rprime
``````
• 3.) Build the source code:
``````\$ cargo build --release
``````

## Installation

Move the executable on the path `rprime/target/release/rprime` to the directory where you keep your binary executables. If you are on Linux or Mac OSX, you might have to change permissions like this: `chmod a+x rprime`. If you have Rust's package manager installed, running `cargo install rprime` from a terminal window should also install RPrime.

## How it works

From an algorithmic point of view, RPrime is very simple. It first finds all factors of a given number and dumps these factors into a list. Finally, it checks whether this list's only factors are 1 and the number itself. Depending on whether this is the case a boolean to that effect is returned.

## Usage

### Command-line usage

Using `rprime` is quite simple:

• Check if 23 is a prime number. `i` is short for `is_prime`. Returns `true` in this case.
``````\$ rprime i 23
true
``````
• Check if 28 is a prime number. Returns `false` in this case.
``````\$ rprime i 28
false
``````
• Get the next prime number. `n` is short for `next`.
``````\$ rprime n 24
29
``````

### Library usage

To use RPrime from your Rust code, add this line to your project's `Cargo.toml`:

``````[dependencies]
rprime = "*"
``````

Finally, use RPrime's functions like this:

• Import them:
``````use rprime::rprime::*;
``````
• Use them:
• `is_prime`: Returns `true` or `false` after checking whether a number of type `i128` is a prime number.
• `next_prime`: Returns the next biggest prime as a number of type `i128` after a number of type `i128`.
• `number_factors`: Returns a vector of numbers of type `i128` of all factors of a number of type `i128`.

## Changelog

### Version 1.0

• initial release
• upload to GitHub

## Note

• RPRIME by Alexander Abraham a.k.a. "The Black Unicorn"