valueDiff for arrays?

Niggemann, Bernd Bernd.Niggemann at uni-wh.de
Mon Aug 6 20:21:15 EDT 2018


How embarrassing, again an error. I should go to sleep now.

 repeat pn mod 10000
      put tYes after tIsItPrime <-- corrected line
   end repeat

Here is the hopfully truly truly last correction.

---------------------------
function get_primes pN -- bn modified brian
   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 tYes 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
----------------------

at least it saves a couple of seconds

Kind regards
Bernd




More information about the use-livecode mailing list