Post Reply 
(32SII/DM32) Prime Factorization (edit)
11-17-2023, 03:41 AM (This post was last modified: 11-18-2023 03:36 PM by Eddie W. Shore.)
Post: #1
(32SII/DM32) Prime Factorization (edit)
Instructions:

1. Enter a positive integer on the X stack.
2. Run the program (XEQ P) and a prime factor is displayed. Press [ R/S ] to continue. At this point the calculator is set to FIX 0 mode. Repeat step 2.
3. The program ends when the integer reappears. The calculator is reset to FIX 4.

3 labels are needed.

Note: One instruction has been corrected, thank you, Thomas Klemm!

Code:
P01  LBL P
P02  FIX 0
P03  STO B
P04  STO A
P05  2
P06  STO F

B01  LBL B
B02  RCL A
B03  RCL÷ F
B04  ENTER
B05  FP
B06  x=0?
B07  GTO A
B08  1
B09  STO+ F
B10  GTO B

A01  LBL A
A02  RCL F
A03  STOP
A04  R↓
A05  R↓
A06  STO A
A07  1
A08  -
A09  x≠0?
A10 GTO B
A11 RCL B
A12 FIX 4
A13 RTN


Labels used: P, B, A
Variables: F (factor), A, B

Examples

26: 2, 13, 26 (26 = 2 × 13)

89: 89 (89 is prime)

175: 5, 5, 7, 175 (175 = 5^2 × 7)

1020: 2, 2, 3, 5, 17, 1020 (1020 = 2^2 × 3 × 5 × 17)
Visit this user's website Find all posts by this user
Quote this message in a reply
11-17-2023, 04:18 AM
Post: #2
RE: (32SII/DM32) Prime Factorization
Nice program Eddie! Looks like it can easily be converted to run on other (incuding older) HP calculators.

Namir
Find all posts by this user
Quote this message in a reply
11-17-2023, 08:50 AM
Post: #3
RE: (32SII/DM32) Prime Factorization
Either I've done something completely wrong or there is a bug in the program.
No matter what I put in, it'll return "2,".
Pressing r/s results in the originally entered integer to return to the stack.
Hitting xeq p just continues to return "2,".
Running xeq p with "0" on the stack returns "divide by 0".

Yes, I've quadruplechecked the program listing. It's correct.
No, nothing else in the calc. Brand new state and all vars cleared.
State file in "code" tag and also attached.

Code:

# STACK
SL: 1

# REGS

# FLAGS

# MODE
MTRIG: DEG
MFMT: FIX 4
MDOTINV

# EQUATION LIST
EQNPTR: 0
EQN
EQNEND

# PROGRAM
PTR: 29
PGM
  LBL P
  FIX 0
  STO B
  STO A
  2
  STO F
  LBL B
  RCL A
  RCL\div; B
  ENTER
  FP
  x=0?
  GTO A
  1
  STO+ F
  GTO B
  LBL A
  RCL F
  STOP
  R\down;
  R\down;
  STO A
  1
  -
  x\neq;0?
  GTO B
  RCL B
  FIX 4
  RTN
PGMEND

.zip  Pfact.zip (Size: 364 bytes / Downloads: 3)

Esben
15C CE, 28s, 35s, 49G+, 50G, Prime G2 HW D, SwissMicros DM32, DM42, DM42n, WP43 Pilot
Elektronika MK-52 & MK-61
Find all posts by this user
Quote this message in a reply
11-17-2023, 08:18 PM
Post: #4
RE: (32SII/DM32) Prime Factorization
(11-17-2023 08:50 AM)DA74254 Wrote:  Either I've done something completely wrong or there is a bug in the program.

(11-17-2023 03:41 AM)Eddie W. Shore Wrote:  
Code:
B03  RCL÷ B

That should rather be:
Code:
B03  RCL÷ F

Here's a program for the HP-42S:
Code:
00 { 42-Byte Prgm }
01▸LBL "P"
02 STO 00
03 STO 01
04 2
05 STO 02
06▸LBL B
07 RCL 00
08 RCL÷ 02
09 ENTER
10 IP
11 X=Y?
12 GTO A
13 1
14 STO+ 02
15 GTO B
16▸LBL A
17 STO 00
18 RCL 02
19 STOP
20 RCL 00
21 1
22 X≠Y?
23 GTO B
24 RCL 01
25 END

I made a few minor adjustments but there's still room for improvements.
Find all posts by this user
Quote this message in a reply
11-18-2023, 03:36 PM
Post: #5
RE: (32SII/DM32) Prime Factorization (edit)
Thank you, Thomas! I have corrected the typo on the original post.
Visit this user's website Find all posts by this user
Quote this message in a reply
11-18-2023, 03:39 PM
Post: #6
RE: (32SII/DM32) Prime Factorization (edit)
(11-17-2023 04:18 AM)Namir Wrote:  Nice program Eddie! Looks like it can easily be converted to run on other (incuding older) HP calculators.

Namir

Thank you, Namir! The program was ported from a HP 15C version.
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 




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