Integer factorization (Wheel factorization)

Contributions to this software library are always welcome. Please ensure that you post program listings rather than .raw files. They give a reasonable idea of what your program does without having to load them into a DM42 and you can also include comments in your code. Check out the following link for a decoder/encoder: https://technical.swissmicros.com/decoders/dm42/

You can then copy/paste the listing and post it in "code" tags.
Post Reply
dk-
Posts: 16
Joined: Wed Sep 23, 2020 7:46 pm

Integer factorization (Wheel factorization)

Post by dk- » Sat Sep 26, 2020 9:00 pm

Hi,

I spent some time writing up a simple wheel factorization (basis 2,3,5). I figured someone else might enjoy it. It's fairly useless, but if you have printer on you get a nice writeout of the prime factors of the supplied integer (number supplied in X). If printer is off you will need to press R/S after each prime factor (and also for a few of the printouts in the beginning). The code will also beep after each discovered prime factor.

It uses registers 00 to 10.

The code could probably be much simpler, and RSA seems to be safe for now...

Code: Select all

00 { 223-Byte Prgm }
01▸LBL "FACT"
02 SF 21
03 STO 00
04 "INTEGER:"
05 AVIEW
06 RCL 00
07 XEQ 00
08 "PRIME FACTORS:"
09 AVIEW
10 4
11 STO 01
12 2
13 STO 02
14 4
15 STO 03
16 2
17 STO 04
18 4
19 STO 05
20 6
21 STO 06
22 2
23 STO 07
24 6
25 STO 08
26 GTO A
27▸LBL B
28 2
29 XEQ 00
30 STO÷ 00
31▸LBL A
32 RCL 00
33 2
34 MOD
35 X=0?
36 GTO B
37 GTO C
38▸LBL D
39 3
40 XEQ 00
41 STO÷ 00
42▸LBL C
43 RCL 00
44 3
45 MOD
46 X=0?
47 GTO D
48 GTO E
49▸LBL F
50 5
51 XEQ 00
52 STO÷ 00
53▸LBL E
54 RCL 00
55 5
56 MOD
57 X=0?
58 GTO F
59 7
60 STO 09
61 1
62 STO 10
63▸LBL G
64 RCL 09
65 X↑2
66 RCL 00
67 X<>Y
68 -
69 X<0?
70 GTO H
71 RCL 00
72 RCL 09
73 MOD
74 CF 00
75 X=0?
76 SF 00
77 FS? 00
78 XEQ I
79 FC? 00
80 XEQ J
81 GTO G
82▸LBL I
83 RCL 09
84 XEQ 00
85 STO÷ 00
86 RTN
87▸LBL J
88 RCL IND 10
89 STO+ 09
90 RCL 10
91 1
92 +
93 9
94 MOD
95 STO 10
96 X≠0?
97 RTN
98 1
99 STO+ 10
100 RTN
101▸LBL 00
102 CLA
103 AIP
104 TONE 1
105 AVIEW
106 RTN
107▸LBL H
108 RCL 00
109 XEQ 00
110 "DONE[LF][LF][LF][LF]"
111 AVIEW
112 END

Post Reply