Compare commits
4 Commits
966574dd1f
...
develop
| Author | SHA1 | Date | |
|---|---|---|---|
| 0cc8e94224 | |||
| 1348f4343a | |||
| 83b5e4a561 | |||
| 084aa14026 |
41
README.md
41
README.md
@@ -1,38 +1,29 @@
|
|||||||
# Indivisible
|
# Indivisible
|
||||||
|
|
||||||
Indivisible is an optimized prime number generator and tester written in Rust.
|
Indivisible is an optimized prime number generator and tester.
|
||||||
|
|
||||||
## Build & Installation
|
## Build & Installation
|
||||||
|
|
||||||
To build the project you will require the Rust compiler and build
|
Build a binary release using the following command:
|
||||||
system, `cargo`. At which point you simply run `cargo build` in the root
|
|
||||||
directory of the project. To create an optimized release build append
|
|
||||||
the `--release` flag to the previous command.
|
|
||||||
|
|
||||||
Once a release build has been compiled, you may install Indivisible and
|
```console
|
||||||
the manpage documentation by running the `install` script. In a similar
|
$ cargo build -r
|
||||||
manner, you can run the `uninstall` script to remove the previously
|
```
|
||||||
installed binary and documentation.
|
|
||||||
|
|
||||||
## Usage
|
Once compiled, you can install it using the `install` script. By default this
|
||||||
|
will install to `/usr/local/{bin,share}`, but you can optionally change the
|
||||||
|
`PREFIX` used as follows:
|
||||||
|
|
||||||
The purpose of Indivisible is to find the nth prime and all the primes
|
```console
|
||||||
before it. The basic usage is `indivisible <n>` where `n` is the ordinal
|
$ PREFIX="~/.local" ./install
|
||||||
of the prime you'd like to find. To display all primes before `n`, you
|
```
|
||||||
can run verbose mode by using the `--verbose` or simply `-v` option.
|
|
||||||
|
|
||||||
Since Indivisible generates primes using previously computed primes, you
|
Additionally there is an `uninstall` script available. If you have used a custom
|
||||||
can also import prime numbers previously computed with the `--import` or
|
`PREFIX` this must also be specified to uninstall in the same manner. To see
|
||||||
`-i` option. To store already computed primes you are expected to use
|
where you've installed it you can always use the following command:
|
||||||
piping like any UNIX user would expect. Here is an example:
|
|
||||||
|
|
||||||
```bash
|
```console
|
||||||
# store first 100 primes in ./primes
|
$ which indivisible
|
||||||
indivisible -v 100 > ./primes
|
|
||||||
# appends next 400 primes
|
|
||||||
indivisible -i ./primes -v 500 >> ./primes
|
|
||||||
# display the 600th prime
|
|
||||||
indivisible -i ./primes 600
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Legacy
|
## Legacy
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
/**
|
/**
|
||||||
* @brief Work on a segment.
|
* @brief Work on a segment.
|
||||||
*
|
*
|
||||||
|
* @param known_primes:&Vec<u64> List of known primes at least until sqrt(end).
|
||||||
* @param start:usize Beginning of the segment (inclusive).
|
* @param start:usize Beginning of the segment (inclusive).
|
||||||
* @param end:usize End of the segment (exclusive).
|
* @param end:usize End of the segment (exclusive).
|
||||||
*
|
*
|
||||||
@@ -28,8 +29,14 @@ pub fn work_segment(known_primes:&Vec<u64>, start:usize, end:usize) -> Vec<u64>
|
|||||||
let mut sieve = vec![true; end - start];
|
let mut sieve = vec![true; end - start];
|
||||||
let mut found_primes = Vec::new();
|
let mut found_primes = Vec::new();
|
||||||
|
|
||||||
|
let sqrt_end = f64::sqrt(end as f64) as usize;
|
||||||
|
|
||||||
for p in known_primes {
|
for p in known_primes {
|
||||||
let prime = *p as usize;
|
let prime = *p as usize;
|
||||||
|
if prime > sqrt_end {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
let modu = start % prime;
|
let modu = start % prime;
|
||||||
let mut mult = if modu == 0 {
|
let mut mult = if modu == 0 {
|
||||||
start
|
start
|
||||||
|
|||||||
24
test.sh
24
test.sh
@@ -17,7 +17,7 @@ fi
|
|||||||
tests=0
|
tests=0
|
||||||
passed=0
|
passed=0
|
||||||
|
|
||||||
## TEST 1
|
## TEST
|
||||||
((tests++))
|
((tests++))
|
||||||
echo -n "${tests}: Find all prime numbers before 70..."
|
echo -n "${tests}: Find all prime numbers before 70..."
|
||||||
expect="2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 "
|
expect="2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 "
|
||||||
@@ -30,7 +30,20 @@ else
|
|||||||
echo " FAIL"
|
echo " FAIL"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
## TEST 2
|
## TEST
|
||||||
|
((tests++))
|
||||||
|
echo -n "${tests}: Find last prime before 1,000,000,000..."
|
||||||
|
expect="999999937"
|
||||||
|
|
||||||
|
if [ "$("$BINARY" 1000000000)" = "$expect" ]
|
||||||
|
then
|
||||||
|
echo " pass"
|
||||||
|
((passed++))
|
||||||
|
else
|
||||||
|
echo " FAIL"
|
||||||
|
fi
|
||||||
|
|
||||||
|
## TEST
|
||||||
((tests++))
|
((tests++))
|
||||||
echo -n "${tests}: 11 is prime..."
|
echo -n "${tests}: 11 is prime..."
|
||||||
if "$BINARY" -t 11
|
if "$BINARY" -t 11
|
||||||
@@ -41,7 +54,7 @@ else
|
|||||||
echo " FAIL"
|
echo " FAIL"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
## TEST 3
|
## TEST
|
||||||
((tests++))
|
((tests++))
|
||||||
echo -n "${tests}: 9 is not prime..."
|
echo -n "${tests}: 9 is not prime..."
|
||||||
if ! "$BINARY" -t 9
|
if ! "$BINARY" -t 9
|
||||||
@@ -54,3 +67,8 @@ fi
|
|||||||
|
|
||||||
## RESULTS
|
## RESULTS
|
||||||
echo "Results: $passed/$tests"
|
echo "Results: $passed/$tests"
|
||||||
|
|
||||||
|
if [ $passed -ne $tests ]
|
||||||
|
then
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user