rprime

Crates.iorprime
lib.rsrprime
version1.0.0
sourcesrc
created_at2022-03-01 17:15:48.605987
updated_at2022-03-01 17:25:38.575999
descriptionProvides useful functions for prime numbers.
homepagehttps://github.com/iamtheblackunicorn/rprime
repositoryhttps://github.com/iamtheblackunicorn/rprime
max_upload_size
id541664
size8,212
✭ THE BLACK UNICORN ✭ (iamtheblackunicorn)

documentation

https://github.com/iamtheblackunicorn/rprime

README

RPRIME

Fun with prime numbers in Rust.

GitHub CI

About

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"
  • Licensed under the MIT license.
Commit count: 0

cargo fmt