6 Commits

4 changed files with 34 additions and 4 deletions

View File

@@ -1,6 +1,8 @@
# Indivisible
Indivisible is an optimized prime number generator and tester.
Indivisible is an optimized prime number generator and tester using a segmented
version of the [Sieve of
Eratosthenes](https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes).
## Build & Installation

View File

@@ -21,6 +21,7 @@ do
case "$opt" in
s)
OPTIONS=("${OPTIONS[@]}" -s "$OPTARG")
SIEVE=$OPTARG
;;
t)
TRIALS="$OPTARG"
@@ -33,6 +34,8 @@ do
done
echo "Calculating primes up to 1,000,000,000"
echo "Trials: $TRIALS"
echo "Sieve segment size: ${SIEVE:-"default"}"
TOTAL="0"
for _ in $(seq "$TRIALS")
do

View File

@@ -19,6 +19,7 @@
/**
* @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 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 found_primes = Vec::new();
let sqrt_end = (end as f64).sqrt() as usize;
for p in known_primes {
let prime = *p as usize;
if prime > sqrt_end {
break;
}
let modu = start % prime;
let mut mult = if modu == 0 {
start

24
test.sh
View File

@@ -17,7 +17,7 @@ fi
tests=0
passed=0
## TEST 1
## TEST
((tests++))
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 "
@@ -30,7 +30,20 @@ else
echo " FAIL"
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++))
echo -n "${tests}: 11 is prime..."
if "$BINARY" -t 11
@@ -41,7 +54,7 @@ else
echo " FAIL"
fi
## TEST 3
## TEST
((tests++))
echo -n "${tests}: 9 is not prime..."
if ! "$BINARY" -t 9
@@ -54,3 +67,8 @@ fi
## RESULTS
echo "Results: $passed/$tests"
if [ $passed -ne $tests ]
then
exit 1
fi