Prime Factors
05-18-2015, 06:10 PM (This post was last modified: 05-19-2015 01:13 PM by Dave Britten.)
Post: #1
 Dave Britten Senior Member Posts: 1,927 Joined: Dec 2013
Prime Factors
In an attempt to rival Doom for the largest number of systems to which it's been ported, here's the usual HP 67 "mod 30" prime factors program for the 41C/CV/CX.

Enter a positive integer, and XEQ FCTR. Press R/S to view each factor. Zero will be displayed when there are no more factors.

Note this is a pretty straight port, and hasn't been fancied up with any 41-specific capabilities (yet).

EDIT: Here's a slightly improved version with a couple optimizations, and multiplicity display for factors (e.g. 3^2, 7^3, etc).

Code:
01 LBL FCTR 02 CF 05 03 FIX 0 04 STO 00 05 SQRT 06 STO 01 07 0 08 STO 02 09 STO 03 10 2 11 XEQ 02 12 1 13 XEQ 02 14 2 15 XEQ 02 16 2 17 XEQ 02 18 RCL 00 19 1 20 X=Y? 21 GTO 09 22 LBL 01 23 4 24 XEQ 02 25 2 26 XEQ 02 27 4 28 XEQ 02 29 2 30 XEQ 02 31 4 32 XEQ 02 33 6 34 XEQ 02 35 2 36 XEQ 02 37 6 38 XEQ 02 39 RCL 00 40 1 41 X=Y? 42 GTO 09 43 RCL 01 44 RCL 02 45 X<=Y? 46 GTO 01 47 RCL 00 48 STO 02 49 0 50 XEQ 02 51 GTO 09 52 LBL 02 53 ST+ 02 54 RCL 00 55 RCL 02 56 MOD 57 X!=0? 58 GTO 05 59 LBL 03 60 RCL 02 61 ST/ 00 62 RCL 00 63 SQRT 64 STO 01 65 1 66 ST+ 03 67 SF 05 68 0 69 GTO 02 70 LBL 05 71 FC?C 05 72 RTN 73 RCL 03 74 RCL 02 75 CLA 76 ARCL X 77 |-^ 78 ARCL Y 79 0 80 STO 03 81 PROMPT 82 RTN 83 LBL 09 84 CLX 85 RTN 86 END
05-18-2015, 08:31 PM
Post: #2
 Thomas Klemm Senior Member Posts: 1,447 Joined: Dec 2013
RE: Prime Factors
(05-18-2015 06:10 PM)Dave Britten Wrote:  Note this is a pretty straight port, and hasn't been fancied up with any 41-specific capabilities (yet).

You might have a look at a program for the HP-42s which uses the same idea.

Cheers
Thomas
05-19-2015, 02:58 AM
Post: #3
 Dave Britten Senior Member Posts: 1,927 Joined: Dec 2013
RE: Prime Factors
(05-18-2015 08:31 PM)Thomas Klemm Wrote:
(05-18-2015 06:10 PM)Dave Britten Wrote:  Note this is a pretty straight port, and hasn't been fancied up with any 41-specific capabilities (yet).

You might have a look at a program for the HP-42s which uses the same idea.

Cheers
Thomas

Thanks Thomas. Clever use of t-copy there. I see a couple things that could be issues for a 41 port: the use of recall arithmetic, as mentioned in that thread, AIP, which requires the appropriate module or alternative code, and the alpha register being limited to 24 characters. I don't recall the 42S alpha limit, but I think I remember it being larger.

I changed my version a bit to display multiplicity of factors as they're found (3^2, 5^3, etc.) and also replaced the / FRC bits with MOD, which appears to be about 20% faster. I'll probably post the updated code tomorrow.
 « Next Oldest | Next Newest »

User(s) browsing this thread: 1 Guest(s)