RPN Programming exercise (HP-42S) Message #1 Posted by Gerson W. Barbosa on 23 Feb 2012, 7:45 p.m.
Given two four-digit integer numbers on the stack, write an HP-42S program that returns their product in no more than 20 seconds on a real HP-42S.
Restriction: use no *, no BASE*, no /, no BASE/, no %, no MOD, no LN, no E^X, no LOG, no 10^X.
Currently I have two programs that meet the requirements:
00 { 77-Byte Prgm }
01>LBL "MLTA"
...
29 ROTXY
...
35 END
and, since ROTXY has been allowed,
00 { 50-Byte Prgm }
01>LBL "MLTB"
...
29 .END.
The latter has the advantage of being faster and shorter. Also, it accepts a wider range of non-fixed format operands.
Examples:
1234 ENTER 5678 XEQ MLTA --> 7,006,652
9999 ENTER XEQ MLTA --> 99,980,001
12 ENTER 3456789 XEQ MLTB --> 41,481,468
1234 ENTER 5678 XEQ MLTB --> 7,006,652
Gerson.
(7:57pm) Edited to add more restrictions:
No STO*, no STO/, no Y^X.
Edited again (the LAST time) for yet one more restriction
and no multiplication of any kind (except binary shifts).
Edited: 23 Feb 2012, 8:12 p.m. after one or more responses were posted
|