primetest2.frink

Download or view primetest2.frink in plain text format


use sieve.frink

// Test to check isPrime.
// This version uses a precalculated sieve.

// TODO: Profile this puppy and make it faster.

highest = 2^31 - 1;

sieve = array[sieve[floor[sqrt[highest]]]]

//println[sieve]

for n = 2 to highest
{
   if n % 10000 == 0
      print["$n\t"]
   
   if isPrimeByDivision[n, sieve] != isPrime[n]
      println["Error!  $n"];
}

isPrimeByDivision[n, sieve] :=
{
   for i = sieve
   {
      if (i >= n)
         return true;
      
      if (n mod i == 0)
         return false
   }

   return true
}
      


Download or view primetest2.frink in plain text format


This is a program written in the programming language Frink.
For more information, view the Frink Documentation or see More Sample Frink Programs.

Alan Eliasen was born 20217 days, 23 hours, 59 minutes ago.