The Museum of HP Calculators

HP Forum Archive 15

[ Return to Index | Top of Index ]

S&SMC #9 HP41cx
Message #1 Posted by Jonathan Watmough on 19 June 2005, 1:58 a.m.

Hi Valentin,

I am a lurker as far as your challenges, but I have greatly enjoyed reading them.

I recently bought a HP41cx, so I thought I'd have a 'go' at trying to get #9 running on a HP41. This is the first program I've written on a calculator since about 1986 when I owned a Casio FX4000p.

I'll feel kinda stupid if this is wrong, especially since I 'cheated' and looked at your original solution briefly, but I can't seem to find the original posts about this challenge. Sadly my school calculus is very rusty, so I played with EMU48 and plotted a few polynomials before I had any idea at all what was going on.

The program ran for about an hour and 20 minutes before getting the following answers :

A=1 B=-5 C=8 D=-7

I skipped the part about finding an exact root ;-) Any suggestions, optimisations, rewrites etc are very welcome.

Best Wishes Jonathan

I used the following registers and labels :

Registers:

01 A hardcoded to start at 1 02 B -M to M 03 C ditto 04 D ditto 05 x1 3.1 06 x2 3.2 07 f(x1) 08 f(x2) 09 M 9

Labels:

LBL SM start of program LBL 01 main loop LBL 02 compute f(x1) LBL 03 compute f(x2) LBL 04 success!

The program:

01 LBL SM set up variables 02 1 03 STO 01 04 RCL 09 05 CHS 06 STO 02 07 STO 03 08 STO 04 09 3.1 10 STO 05 11 3.2 12 STO 06 13 LBL 01 main loop 14 XEQ 02 calc f(x1) 15 XEQ 03 calc f(x2) 16 RCL 07 17 RCL 08 18 / divide them and look for -ve 19 0 20 X<>Y 21 X<=Y? -ve? 22 GTO 04 success !! x1 and x2 straddle the root 23 RCL 04 24 1 25 + 26 STO 04 D=D+1 27 RCL 09 28 X<>Y 29 X<=Y? <=M ? 30 GTO 01 loop 31 X<>Y 32 CHS 33 STO 04 else D=-M 34 1 35 RCL 03 36 + 37 STO 03 C=C+1 38 RCL 09 39 X<>Y 40 X<=Y? C<=M? 41 GTO 01 loop 42 X<>Y 43 CHS 44 STO 03 else C=-M 45 1 46 RCL 02 47 + 48 STO 02 B=B+1 49 RCL 09 50 X<>Y 51 X<=Y? B<=M? 52 GTO 01 loop 53 X<>Y 54 CHS 55 STO 02 B=-M 56 1 57 RCL 01 58 + 59 STO 01 A=A+1 60 GTO 01 loop -- should be a check here 61 "FAILED" 62 AVIEW 63 LBL 04 we come here if we find a root in [x1,x2] 64 "FOUND IT" 65 AVIEW 66 RTN 67 END 68 LBL 02 Calculate f(x1) 69 RCL 05 70 3 71 Y^X 72 RCL 01 73 * 74 RCL 05 75 X^2 76 RCL 02 77 * 78 + 79 RCL 05 80 RCL 03 81 * 82 + 83 RCL 04 84 + 85 STO 07 86 RTN 87 LBL 03 Calculate f(x2) 88 RCL 06 89 3 90 Y^X 91 RCL 06 92 X^2 93 RCL 02 94 * 95 + 96 RCL 06 97 RCL 03 98 * 99 + 100 RCL 04 101 + 102 STO 08 103 RTN 104 END

      
Re: S&SMC #9 HP41cx
Message #2 Posted by Valentin Albillo on 20 June 2005, 4:49 a.m.,
in response to message #1 by Jonathan Watmough

Hi, Jonathan:

Thanks for your interest in my challenges. I also don't keep copies of the threads, so I'm not sure what the exact number was, but certainly your program has nothing to do with S&SMC#9, which is quite recent and asked for a 10-digit number fitting some divisibility criteria.

Your solution surely has to do with a much ancient S&SMC, but don't know exactly which, so I can't comment on the solutions posted at the time though I suppose that your program finds it correctly, whatever it was it had to find :-)

Thanks again for your interest, and keep posting your HP-41CX solutions to past, present, and future challenges. And by the way, congratulations on your recent acquisition.

Best regards from V.


[ Return to Index | Top of Index ]

Go back to the main exhibit hall