valueDiff for arrays?
Niggemann, Bernd
Bernd.Niggemann at uni-wh.de
Mon Aug 6 19:24:57 EDT 2018
This also helps a bit. Where is Hermann?
---------------------
function get_primes pN
local tMroot, tPrimes, tIsItPrime, tYes, tNo
put numtobyte(66) into tYes
put numtobyte(65) into tNo
if pN < 2 then return empty
if pN = 2 then return 2
put 2 into tPrimes
put trunc(sqrt(pN)) - 1 into tMroot
if pN > 10000 then
local tTenThousand
repeat 10000
put tYes after tTenThousand
end repeat
repeat pn div 10000
put tTenthousand after tIsItPrime
end repeat
end if
repeat pn mod 10000
put tTenthousand after tIsItPrime
end repeat
repeat with i = 3 to tMroot step 2
if byte i of tIsItPrime is tNo then next repeat
put cr & i after tPrimes
repeat with j = i^2 to pN step i
put tNo into byte j of tIsItPrime
end repeat
end repeat
repeat with i = tMroot + (tMroot + 1) mod 2 to pN - 1 step 2
if byte i of tIsItPrime is tYes then put cr & i after tPrimes
end repeat
return tPrimes
end get_primes
--------------------
This is a modified Brian´s version built upon Alex's version
Note that Brian seems to find one additional prime.
Kind regards
Bernd
More information about the use-livecode
mailing list