Interesting. I tried a variation using arrays, and it's three times slower than yours.

function get_primes pN
   local tMroot, tPrimes, tIsItPrime

   if pN < 2 then return empty
   if pN = 2 then return 2
   put trunc(sqrt(pN)) - 1 into tMroot

   repeat with i=1 to pN step 2
      put 1 into tIsItPrime[i]
   end repeat

   repeat with i = 3 to tMroot step 2
      if tIsItPrime[i] is empty then next repeat
      repeat with j = i^2 to pN step i
         delete variable tIsItPrime[j]
      end repeat
   end repeat

   return the keys of tIsItPrime
end get_primes

--
 Mark Wieder
 ahsoftw...@gmail.com

_______________________________________________
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

Reply via email to