valueDiff for arrays?

Mark Wieder ahsoftware at sonic.net
Mon Aug 6 21:24:50 EDT 2018


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
  ahsoftware at gmail.com




More information about the use-livecode mailing list