primetest.frink

Download or view primetest.frink in plain text format


// Test to check isPrime using Sieve of Eratosthenes.
// This is memory-limited in the highest number it can calculate.

n = eval[input["Enter highest number: "]]
testPrime[n]

testPrime[n] :=
{
   // Initialize array
   array = array[0 to n]
   array@1 = 0

   for i = 2 to ceil[sqrt[n]]
      if array@i != 0
         for j = 2*i to n step i
            array@j = 0

   for i = 2 to n
      if isPrime[i] != (array@i != 0)
         println["Error!  n=$i  Sieve=" + (array@i != 0)]
}


Download or view primetest.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 20143 days, 10 hours, 6 minutes ago.