prime_checker/
lib.rs

1#![allow(warnings)]
2//! Rust library crate to hold simple functions to check the prime-ness of a given unsigned, 64-bit integer.
3
4mod libs;
5
6pub fn description(show: bool) -> String {
7    //! Prints a description of the crate to the console and returns the same.
8    //!
9    //! __Arguments:__
10    //!
11    //! 1. `show: bool` - Whether to print the description to the console or not.
12    //!
13    //! __Returns__:
14    //!
15    //! 1. `String` - A brief description of the library as defined in `libs::constants::DESCRIPTION`
16    //!
17    let description_str = String::from(libs::constants::DESCRIPTION);
18    if show == true {
19        println!("{}", description_str);
20    }
21    return description_str;
22}
23
24pub fn is_prime(num: u64) -> (bool, Vec<u64>) {
25    //! Checks to see if a given number is a prime number.
26    //!
27    //! __Arguments:__
28    //!
29    //! 1. `num: u64` - The number to check.
30    //!
31    //! __Returns:__
32    //!
33    //! 1. `bool` - Is true if the number is prime, and false if it is not.
34    //! 2. `Vec<u64>` - The list of factors of the number.
35    //!
36    //! __Example:__
37    //!
38    //! ```rust
39    //! let (check,factors) = prime_checker::is_prime(7);
40    //!
41    //! assert_eq!(factors, vec![1, 7]);
42    //! assert_eq!(check, true);
43    //! ```
44    //!
45    let (check, factors) = libs::primes::check_if_prime(num);
46    return (check, factors);
47}
48
49pub fn is_hcn(num: u64) -> (bool, Vec<u64>) {
50    //! Checks to see if a given number is a highly-composite (anti-prime) number.
51    //!
52    //! __Arguments:__
53    //!
54    //! 1. `num: u64` - The number to check.
55    //!
56    //! __Returns:__  
57    //!
58    //! 1. `bool` - Is true if the number is anti-prime, and false if it is not.
59    //! 2. `Vec<u64>` - The list of factors of the number.
60    //!
61    //! __Example:__
62    //!
63    //! ```rust
64    //! let (check,factors) = prime_checker::is_hcn(12);
65    //!
66    //! assert_eq!(factors, vec![1, 2, 3, 4, 6, 12]);
67    //! assert_eq!(check, true);
68    //! ```
69    //!
70    let (check, factors) = libs::primes::check_if_anti_prime(num);
71    return (check, factors);
72}
73
74pub fn get_hcn(num: u64) -> Vec<u64> {
75    //! Find all highly composite numbers until a given value `num`.
76    //!
77    //! __WARNING:__ Computationally Expensive [^1]
78    //!
79    //! __Arguments:__
80    //!
81    //! 1. `num: u64` - The number to check till.
82    //!
83    //! __Returns:__
84    //!
85    //! 1. `Vec<u64>` - The list of all anti-prime numbers until that number.
86    //!
87    //! __Example:__
88    //!
89    //! ```rust
90    //! let anti_primes: Vec<u64> = prime_checker::get_hcn(100);
91    //!
92    //! assert_eq!(anti_primes, vec![1, 2, 4, 6, 12, 24, 36, 48, 60]);
93    //! ```
94    //!
95    //! [^1]: _Takes ~64 seconds to check ~6000 values beyond the last known anti-prime as defined in `libs::constants::KNOWN_ANTIPRIMES`_
96    let anti_primes: Vec<u64> = libs::primes::find_anti_primes_till(num);
97    return anti_primes;
98}
99
100pub fn get_primes(num: u64) -> Vec<u64> {
101    //! Finds all the prime numbers till a given number.
102    //!
103    //! __Arguments:__
104    //!
105    //! 1. `num: u64` - The number to check till.
106    //!
107    //! __Returns:__
108    //!
109    //! 1. `Vec<u64>` - A vector of all the prime numbers till the given number.
110    //!
111    //! __Example:__
112    //!
113    //! ```rust
114    //! let prime_numbers = prime_checker::get_primes(12);
115    //!
116    //! assert_eq!(prime_numbers, vec![2, 3, 5, 7, 11]);
117    //! ```
118    //!
119    let prime_numbers = libs::primes::find_primes_till(num);
120    return prime_numbers;
121}
122
123#[cfg(test)]
124mod tests;