S&SMC #9 HP41cx



#3

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


#4

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.


Possibly Related Threads...
Thread Author Replies Views Last Post
  HP41CX: Strange serial #... Stephan Matthys 1 371 09-13-2013, 01:38 PM
Last Post: Stephan Matthys
  Using PIL-BOX & ILPer to Transfer Programmes from PC to HP41CX? Michael Lopez 5 708 06-25-2012, 09:31 AM
Last Post: Michael Lopez
  Science Project with HP41CX and Arduino? Fouad M. Kaadou 9 942 01-04-2012, 04:04 AM
Last Post: yves
  Strange HP41CX Problem - HELP! Fouad M. Kaadou 2 401 11-20-2011, 05:12 AM
Last Post: Fouad M. Kaadou
  HP41CX - Strange turning-on behaviour Frido Bohn 8 831 05-04-2011, 06:05 PM
Last Post: geoff quickfall
  HP41CX power consumption Egan Ford 6 626 04-12-2011, 11:30 PM
Last Post: Garth Wilson
  Preprogrammed EPROMs for HHE PE unit for the HP41CX Prabhu Bhooplapur 3 434 01-28-2011, 02:08 AM
Last Post: Geir Isene
  Production Dates HP41CX Fullnut vs. Halfnut Frido Bohn 5 602 10-10-2010, 12:59 PM
Last Post: Jim L (OHIO)
  New HP41CX listed on Ebay Nigel Bamber 2 397 09-30-2010, 07:09 AM
Last Post: Jean-Michel
  Dropped HP41CX (carpeted floor), no longer working jim540 29 2,138 01-08-2010, 08:43 AM
Last Post: Mike Morrow

Forum Jump: