valueDiff for arrays?

Niggemann, Bernd Bernd.Niggemann at uni-wh.de
Mon Aug 6 19:49:35 EDT 2018


There was an error in the code I posted.
It should read "if pN >= 10000 then" instead of "if pN > 10000"

this is the corrected version
-----------------
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
---------------

Kind regards
Bernd




More information about the use-livecode mailing list