HP 50g Double factorial
|
05-01-2019, 09:26 PM
(This post was last modified: 05-02-2019 02:55 PM by Giuseppe Donnini.)
Post: #15
|
|||
|
|||
RE: HP 50g Double factorial
(05-01-2019 06:17 PM)Albert Chan Wrote: I am not familiar with RPL code, but is there a loop construct where you test the condition first ? That way, the 0 special case need not be added. Thanks, Albert, for your valuable comments. Sure there is! Here we go: \<< 1 SWAP @ Initialize result. WHILE DUP 2 \>= @ Repeat while factor >= 2. REPEAT DUP ROT * @ Multiply product with current factor. SWAP 2 - @ Decrement factor by 2. END DROP @ Drop remaining factor (by now invalid, i.e. < 2). \>> Saves 9 bytes, but negative arguments will return 1, too, whereas my former implementation left them unchanged. |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)