The Museum of HP Calculators

HP Forum Archive 15

 S&SMC#9: Optimized 42S (and 41C) RPN solutionMessage #1 Posted by Valentin Albillo on 26 May 2005, 9:42 a.m. Hi, The RPN solution I gave for the 42S yesterday was an unoptimized, direct translation of my original solution for the 71B, and would run only on a 42S because it used more subroutine levels than the 41C would allow. On the other and, this optimized translation, despite still using the exact same logic as the 71B version, does include the following improvements over the first one: Appreciably shorter (80 steps, 149 bytes vs. 92 steps, 167 bytes) and faster. Doesn't use subroutine levels in a recursive manner, so its maximum depth is 1, and thus will run on the HP-41C essentially unchanged. The only modification necessary to make it run in the HP-41C is to expand the RCL arithmetic at steps 44 (RCL+ IND 01) and 53 (RCLx IND 03) into two separate steps each (RCL, + and RCL, x, respectively), thus the 41C version will be 82 steps long. 01*LBL "SR" 21 STO IND 02 41 FS? IND ST X 61 3 02 0.009 22 CF 15 42 GTO 03 62 XEQ 06 03 STO 04 23 X=Y? 43 INT 63 RUP 04*LBL 05 24 SF 15 44 RCL+ IND 01 64 GTO 00 05 CF IND ST X 25 3 45 STO IND 03 65*LBL 04 06 ISG ST X 26 FC? 15 46 RCL 00 66 RCL IND 02 07 GT0 05 27 STO- IND 02 47 MOD 67 CF IND ST X 08 1 28 1E5 48 X#0? 68*LBL 03 09 STO 00 29 STO/ IND 02 49 GTO 03 69 ISG IND 02 10 5 30 RCL 04 50 RCL IND 02 70 GTO 01 11 STO 01 31 STO+ IND 02 51 SF IND ST X 71 -3 12 6 32 4 52 10 72 XEQ 06 13 STO 02 33 FS? 15 53 RCLx IND 03 73 GTO 04 14 7 34 STO+ IND 02 54 9 74*LBL 06 15 STO 03 35 RCL 00 55 RCL 00 75 STO+ 01 16 0 36 2 56 X ST Z=3,816,547,290 (in the HP42S) -> 3,816,547,290 (in the HP-41C) after a few seconds in the 42S or a few minutes in the 41C. No other solutions do exist, but you can make certain by continuing the search by pressing [R/S]. After a while it will signal that further solutions are nonexistent by displaying "Nonexistent" (42S) or "NONEXISTENT" (41C), which is achieved by forcing that error message when the search is over, thus saving the steps required to display an alpha prompt. This same program would also run in an HP-15C (despite the effects of using system flags 8 and 9) with a small change to cater for the fact that you can't use the X-register for indirect addressing (simply X<>I, indirect operation using I, X<>I) and also bringing the solution to the X-register before pausing/stopping for the user to see it (the 42S/41C version above displays the solution using a VIEW Z, because it is in the Z-register at that time). Best regards from V.

Go back to the main exhibit hall