OEIS featured in The New York Times
|
07-25-2024, 08:32 PM
Post: #13
|
|||
|
|||
RE: OEIS featured in The New York Times
(07-24-2024 09:08 AM)Gil Wrote: But in fact, no necessity to save the last element calculated, we can just play on its duplication. The above program becomes then: Nice program, simple and fast. Here is a slightly modified version to illustrate a couple of memory saving tips. This is not meant as criticism of your program, just as information that may be of help to you and others. Code:
My first tip turns out not to save any memory in this case but deserves mention. I have always heard that in IF..THEN..(ELSE)..END structures, having exactly one object between IF and ELSE minimizes memory use. It seems that your method of having nothing between IF and ELSE uses no more memory. I do think that my version is more readable but that may not be the case with other programs. My next tip is to use 2 n START rather than 1 n 1 - START which does the same number of iterations but saves 5 bytes. Note that this may not work with FOR loops where the value of the looping variable would be different, but is always safe to use with START loops. A final, simple tip is to use the extended stack operations available on the HP 49 and 50. In this case I replaced DUP DUP with DUPDUP, saving 2.5 bytes. Others include UNROT, PICK3 and NIP. These extended stack operations are faster than their equivalents, as well as saving memory. |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)