(29C) Prime numbers up to 10'000
|
09-03-2018, 07:05 PM
(This post was last modified: 09-03-2018 09:36 PM by Thomas Klemm.)
Post: #5
|
|||
|
|||
RE: (29C) Prime numbers up to 10'000
(09-03-2018 05:24 PM)Dieter Wrote: Since I am not completely sure how the program works maybe Thomas can provide some more detailed hints for an HP67/97 version. If we have only 26 registers we can only store these 23 primes: [5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97] But since register I occupies register 25 instead of 0 the whole list is shifted. Thus the primes start with register 2 instead of 3 and so on. We can't reuse some of the numbers anymore when initialising the registers but that shouldn't be a problem. Code: 01: 2 You have to adjust the registers through out the whole program. In the for i loop we have to initialise register I with 2 now. And then we better switch this with calculating the next n: Code: 36: LBL 1 ; for n loop We have to make sure that the index is smaller than 25. Thus lines 32-33 have to be replaced by: Code: 30: ISZ ; i = i+1 The line numbering will probably be off as well. Since 97² = 9409 we can't go further than that. But the paper will run out anyway at about 9’300 so that's not a problem. If you want to make really sure that register I isn't overwritten you can add the same check at the end of the program: Code: 59: ISZ ; i = i+1 You may have noticed the Python programs in my last post. They might help understanding the algorithm. HTH Thomas PS: When I contains 25 the command RCL (i) will return 25. Thus it will be checked if 25 is a divisor of n. But we already checked if 5 is and that wasn't the case. Furthermore the previous probe was 97 which is bigger and thus n > 25². Thus we will happily increment I once more and get an error the next time we try to execute RCL (i). At least that's what I assume would happen. I haven't tested it yet. |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)