Made a new program for the HP 11C
|
01-07-2014, 10:06 PM
Post: #2
|
|||
|
|||
RE: Made a new program for the HP 11C
A couple of things you can do to significantly increase the speed of this program.
First, if a number is odd, you only need to test by odd numbers, so you can increment register 3 by two instead of one. Of course, this means that you have to treat 2 as a special case since it's even and prime. Second, you only need to test up to the square root of the number, or at worst the next larger integer. Steps 003 and 004 can be replaced by SQRT ; 1 ; + . This won't make much difference for smaller numbers but is significant for larger numbers. For example, to test whether 1001 is prime, you only have to go to 32 instead of 500. Combined with the first optimization, this makes the program about thirty times faster. For 10001 it's about a hundred times faster. Don't take the above as a criticism of your program. It's just that stuff like this becomes second nature by the time you've written your third prime number test. I think I wrote my first one forty years ago... |
|||
« Next Oldest | Next Newest »
|
Messages In This Thread |
Made a new program for the HP 11C - vma - 01-07-2014, 09:21 PM
RE: Made a new program for the HP 11C - kakima - 01-07-2014 10:06 PM
RE: Made a new program for the HP 11C - vma - 01-08-2014, 09:44 AM
RE: Made a new program for the HP 11C - vma - 01-08-2014, 10:03 AM
RE: Made a new program for the HP 11C - Dieter - 01-08-2014, 06:49 PM
RE: Made a new program for the HP 11C - vma - 01-08-2014, 09:36 PM
RE: Made a new program for the HP 11C - walter b - 01-08-2014, 10:13 PM
RE: Made a new program for the HP 11C - Thomas Klemm - 01-09-2014, 07:22 AM
RE: Made a new program for the HP 11C - Dave Britten - 01-09-2014, 02:16 AM
|
User(s) browsing this thread: 4 Guest(s)