The following warnings occurred:
Warning [2] Undefined array key 212752 - Line: 275 - File: inc/plugins/threaded_mode.php PHP 8.1.2-1ubuntu2.14 (Linux)
File Line Function
/inc/class_error.php 153 errorHandler->error
/inc/plugins/threaded_mode.php 275 errorHandler->error_callback
/inc/plugins/threaded_mode.php 23 ThreadedMode::showthread_threaded
/inc/class_plugins.php 142 threaded_mode_showthread_threaded
/showthread.php 918 pluginSystem->run_hooks
Warning [2] Undefined array key 212765 - Line: 275 - File: inc/plugins/threaded_mode.php PHP 8.1.2-1ubuntu2.14 (Linux)
File Line Function
/inc/class_error.php 153 errorHandler->error
/inc/plugins/threaded_mode.php 275 errorHandler->error_callback
/inc/plugins/threaded_mode.php 23 ThreadedMode::showthread_threaded
/inc/class_plugins.php 142 threaded_mode_showthread_threaded
/showthread.php 918 pluginSystem->run_hooks
Warning [2] Undefined variable $thread - Line: 295 - File: inc/plugins/threaded_mode.php PHP 8.1.2-1ubuntu2.14 (Linux)
File Line Function
/inc/class_error.php 153 errorHandler->error
/inc/plugins/threaded_mode.php 295 errorHandler->error_callback
/inc/plugins/threaded_mode.php 23 ThreadedMode::showthread_threaded
/inc/class_plugins.php 142 threaded_mode_showthread_threaded
/showthread.php 918 pluginSystem->run_hooks
Warning [2] Trying to access array offset on value of type null - Line: 295 - File: inc/plugins/threaded_mode.php PHP 8.1.2-1ubuntu2.14 (Linux)
File Line Function
/inc/class_error.php 153 errorHandler->error
/inc/plugins/threaded_mode.php 295 errorHandler->error_callback
/inc/plugins/threaded_mode.php 23 ThreadedMode::showthread_threaded
/inc/class_plugins.php 142 threaded_mode_showthread_threaded
/showthread.php 918 pluginSystem->run_hooks
Warning [2] Undefined variable $fid - Line: 295 - File: inc/plugins/threaded_mode.php PHP 8.1.2-1ubuntu2.14 (Linux)
File Line Function
/inc/class_error.php 153 errorHandler->error
/inc/plugins/threaded_mode.php 295 errorHandler->error_callback
/inc/plugins/threaded_mode.php 23 ThreadedMode::showthread_threaded
/inc/class_plugins.php 142 threaded_mode_showthread_threaded
/showthread.php 918 pluginSystem->run_hooks
Warning [2] Undefined array key 212765 - Line: 331 - File: inc/plugins/threaded_mode.php PHP 8.1.2-1ubuntu2.14 (Linux)
File Line Function
/inc/class_error.php 153 errorHandler->error
/inc/plugins/threaded_mode.php 331 errorHandler->error_callback
/inc/plugins/threaded_mode.php 332 ThreadedMode::buildtree
/inc/plugins/threaded_mode.php 304 ThreadedMode::buildtree
/inc/plugins/threaded_mode.php 23 ThreadedMode::showthread_threaded
/inc/class_plugins.php 142 threaded_mode_showthread_threaded
/showthread.php 918 pluginSystem->run_hooks
Warning [2] Undefined variable $theme - Line: 3 - File: inc/plugins/threaded_mode.php(305) : eval()'d code PHP 8.1.2-1ubuntu2.14 (Linux)
File Line Function
/inc/class_error.php 153 errorHandler->error
/inc/plugins/threaded_mode.php(305) : eval()'d code 3 errorHandler->error_callback
/inc/plugins/threaded_mode.php 305 eval
/inc/plugins/threaded_mode.php 23 ThreadedMode::showthread_threaded
/inc/class_plugins.php 142 threaded_mode_showthread_threaded
/showthread.php 918 pluginSystem->run_hooks
Warning [2] Trying to access array offset on value of type null - Line: 3 - File: inc/plugins/threaded_mode.php(305) : eval()'d code PHP 8.1.2-1ubuntu2.14 (Linux)
File Line Function
/inc/class_error.php 153 errorHandler->error
/inc/plugins/threaded_mode.php(305) : eval()'d code 3 errorHandler->error_callback
/inc/plugins/threaded_mode.php 305 eval
/inc/plugins/threaded_mode.php 23 ThreadedMode::showthread_threaded
/inc/class_plugins.php 142 threaded_mode_showthread_threaded
/showthread.php 918 pluginSystem->run_hooks
Warning [2] Undefined variable $theme - Line: 3 - File: inc/plugins/threaded_mode.php(305) : eval()'d code PHP 8.1.2-1ubuntu2.14 (Linux)
File Line Function
/inc/class_error.php 153 errorHandler->error
/inc/plugins/threaded_mode.php(305) : eval()'d code 3 errorHandler->error_callback
/inc/plugins/threaded_mode.php 305 eval
/inc/plugins/threaded_mode.php 23 ThreadedMode::showthread_threaded
/inc/class_plugins.php 142 threaded_mode_showthread_threaded
/showthread.php 918 pluginSystem->run_hooks
Warning [2] Trying to access array offset on value of type null - Line: 3 - File: inc/plugins/threaded_mode.php(305) : eval()'d code PHP 8.1.2-1ubuntu2.14 (Linux)
File Line Function
/inc/class_error.php 153 errorHandler->error
/inc/plugins/threaded_mode.php(305) : eval()'d code 3 errorHandler->error_callback
/inc/plugins/threaded_mode.php 305 eval
/inc/plugins/threaded_mode.php 23 ThreadedMode::showthread_threaded
/inc/class_plugins.php 142 threaded_mode_showthread_threaded
/showthread.php 918 pluginSystem->run_hooks
Warning [2] Undefined variable $lang - Line: 5 - File: inc/plugins/threaded_mode.php(305) : eval()'d code PHP 8.1.2-1ubuntu2.14 (Linux)
File Line Function
/inc/class_error.php 153 errorHandler->error
/inc/plugins/threaded_mode.php(305) : eval()'d code 5 errorHandler->error_callback
/inc/plugins/threaded_mode.php 305 eval
/inc/plugins/threaded_mode.php 23 ThreadedMode::showthread_threaded
/inc/class_plugins.php 142 threaded_mode_showthread_threaded
/showthread.php 918 pluginSystem->run_hooks
Warning [2] Attempt to read property "messages_in_thread" on null - Line: 5 - File: inc/plugins/threaded_mode.php(305) : eval()'d code PHP 8.1.2-1ubuntu2.14 (Linux)
File Line Function
/inc/class_error.php 153 errorHandler->error
/inc/plugins/threaded_mode.php(305) : eval()'d code 5 errorHandler->error_callback
/inc/plugins/threaded_mode.php 305 eval
/inc/plugins/threaded_mode.php 23 ThreadedMode::showthread_threaded
/inc/class_plugins.php 142 threaded_mode_showthread_threaded
/showthread.php 918 pluginSystem->run_hooks





Re: RPN Programming exercise (HP-42S)



#3

Thanks all of you for your participation and interesting solutions. Most of them supersede mine, as they are shorter, faster and accept a wider range of operands, exactly what I expected them to be. Here are my solutions:

00 { 77-Byte Prgm }
01>LBL "MLTA"
02 0
03 0.099
04 Rv
05>LBL 00
06 STO IND ST T
07 RCL+ ST Y
08 ISG ST T
09 GTO 00
10 RCL ST Z
11 CLA
12 AIP
13 XEQ 02
14 XEQ 02
15 RCL IND ST Y
16 RCL IND ST Y
17 1.1
18 Rv
19>LBL 01
20 RCL+ ST Y
21 ISG ST T
22 GTO 01
23 RTN
24>LBL 02
25 ATOX
26 RCL+ ST X
27 LASTX
28 -3
29 ROTXY
30 +
31 ATOX
32 +
33 528
34 -
35 END
This will accept two numbers in the range [1000..9999] and give their product.

Examples:

1234 ENTER 5678 XEQ MLTA   -->  7,006,652

9999 ENTER XEQ MLTA --> 99,980,001

Here is an equivalent QBASIC program:
   CLS
DEFINT A-D, I
DEFDBL S
DIM M(100)
INPUT A, B
C = VAL(MID$(STR$(B), 2, 2)): REM C = B \ 100
D = VAL(RIGHT$(STR$(B), 2)): REM D = B - 100 * C
S = 0
FOR I = 0 TO 99
M(I) = S
S = S + A
NEXT I
S = M(D)
FOR I = 1 TO 100
S = S + M(C)
NEXT I
PRINT S
END

? 1234,5678
7006652

The next program is an implementation of the Russian Peasant Multiplication Method:

00 { 52-Byte Prgm }
01>LBL "MLTB"
02 0
03 STO 00
04 Rv
05>LBL 00
06 0
07 BIT?
08 XEQ 01
09 BASE+
10 X=0?
11 GTO 02
12 1
13 ROTXY
14 X<>Y
15 -1
16 ROTXY
17 X<>Y
18 GTO 00
19>LBL 01
20 NOT
21 BASE+
22 X<>Y
23 STO+ 00
24 X<>Y
25 0
26 RTN
27>LBL 02
28 RCL 00
29 .END.

This will give the product of any two positive integer numbers, as long as the result doesn't exceed 236-1.
Examples:

12 ENTER 3456789 XEQ MLTB  --> 41,481,468 

1234 ENTER 5678 XEQ MLTB --> 7,006,652

262143 ENTER XEQ MLTB --> 68,718,952,449

Here is a variation of the first program, in case one of the operands is allowed to be entered as two separate two-digit numbers, as proposed somewhere else in this thread:

00 { 47-Byte Prgm }
01>LBL "MLTC"
02 STO 01
03 0
04 STO 00
05 CLX
06 2.099
07 Rv
08>LBL 00
09 RCL+ 01
10 STO IND ST T
11 ISG ST T
12 GTO 00
13 RCL IND ST Z
14 RCL IND ST Z
15 1.1
16 Rv
17>LBL 01
18 RCL+ ST Y
19 ISG ST T
20 GTO 01
21 END

Examples:

12 ENTER 34 ENTER 5678 XEQ MLTC   -->    7,006,652

99 ENTER ENTER 9999 XEQ MLTC --> 99,980,001

Gerson.

P.S.: Programs #1 and #3 require the allocation of 100 numbered registers:

Shift  MODES  \/  SIZE  0100 


Edited: 27 Feb 2012, 5:39 p.m.


#4

I was missing AIP. Used instead of ARCL it would have saved the problems with the 1000s separator or the decimal point. Otherwise, my program wouldn't need big changes.


Possibly Related Threads…
Thread Author Replies Views Last Post
  [PRIME] RPN: another attempt at returning more than one value to the RPN stack Marcus von Cube, Germany 5 2,382 11-05-2013, 02:44 AM
Last Post: Marcus von Cube, Germany
  HHC 2013 RPN Programming Challenge - Final Thought Jeff O. 7 2,309 10-17-2013, 11:02 AM
Last Post: Jeff O.
  HHC / HP Museum Programming Contest for RPN and RPL machines Gene Wright 18 5,450 09-22-2013, 09:39 AM
Last Post: Miguel Toro
  HP 42s programming help for novice Carl D (new) 4 1,565 02-02-2013, 11:39 PM
Last Post: Mike Morrow
  HHC 2012 RPN Programming Contest - 10-Step Way-After-Nashville Solution Jeff O. 32 6,657 10-12-2012, 01:41 AM
Last Post: Paul Dale
  HHC 2012 RPN Programming Challenge Conundrum Jeff O. 15 3,899 10-08-2012, 03:34 PM
Last Post: Gerson W. Barbosa
  HHC 2012 RPN Programming Contest Gene Wright 73 14,142 09-28-2012, 12:43 PM
Last Post: x34
  HHC 2012 programming contests coming soon (RPN and RPL) Gene Wright 9 2,621 09-21-2012, 03:38 PM
Last Post: Paul Dale
  Programming exercise Gerson W. Barbosa 32 6,690 08-23-2012, 07:42 PM
Last Post: Gerson W. Barbosa
  Help with RPN programming hpnut 36 8,558 03-03-2012, 09:31 AM
Last Post: Bill (Smithville, NJ)

Forum Jump: