QuickStep commented on a Page, Prime numbers  -  Jul 06, 2005

Looking better now, still few things to mention:

  • with my previous post saying if divide by \'2\' doesnt match then all even numbers dont match, thats something you can keep in consideration. Check if it is dividable by 2 and if it isnt, only check UNeven numbers afterwards \'inc %prime 2\'. This will make the loop 2x faster.
  • You dont need the if (!%pr) bit because the script should be already halted if a match was found, so you dont need to set the %pr=1 too
  • By comparing it like this \'if $calc(xxx) == $int($calc(xxx)) you are actually doing 2 calculations, which slows the script. This script obviously depends on speed, so set a variable, BUT dont use VAR in the loop itself, do it like this:
    var %prime, %calc
    ;restofcode
    %calc = $calc($1 / %prime)
    if (%calc = $int(%calc))
    etc.

  • Now you can avoid this, but too be extremely picky, in a single if-statement you dont have to use the { } brackets, and it speeds up processing leaving them away, so it would be:
    else inc %prime
    instead of
    else { inc %prime }
 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.