Post Reply 
(34S) Prime Factors
05-30-2014, 01:53 AM (This post was last modified: 06-15-2017 01:21 PM by Gene.)
Post: #1
(34S) Prime Factors
Got my WP-34S fully built today, so naturally, that means you're getting the usual prime factoring algorithm that I've been dragging along to absolutely everything since I found it in that HP-67 program listing.

This one adds a few enhancements: factors are all obtained up front as quickly as possible, and then a simple menu is displayed allowing the user to view the list with the Up and Down arrow keys.

Usage: Enter number to factor into X, XEQ 'FAC'. Once all factors are found, use the up and down arrows to review the results.

It's pretty quick; factoring 167,699,497 down to 7 * 3,851 * 6,221 takes around 2.5 seconds.

BUG FIX EDIT: Swapped steps 88 and 89 to prevent the VWa+ from disappearing when PSE 99 times out.

Code:
001 LBL'FAC'
002 LocR 006
003 CLα
004 α'FAC'
005 α'TOR'
006 α'S:'
007 x<1?
008 GTO 99
009 FP
010 x!=0?
011 GTO 99
012 RCL L
013 STO .00
014 SQRT
015 IP
016 STO .01
017 0
018 STO .02
019 STO .03
020 2
021 XEQ 03
022 1
023 XEQ 03
024 2
025 XEQ 03
026 2
027 XEQ 03
028 RCL .00
029 x=1?
030 GTO 09

031 LBL 01
032 4
033 XEQ 03
034 2
035 XEQ 03
036 4
037 XEQ 03
038 2
039 XEQ 03
040 4
041 XEQ 03
042 6
043 XEQ 03
044 2
045 XEQ 03
046 6
047 XEQ 03
048 RCL .00
049 x=1?
050 GTO 09
051 RCL .01
052 RCL .02
053 x<=? Y
054 GTO 01
055 RCL .00
056 STO .02
057 0
058 XEQ 03
059 GTO 09

060 LBL 03
061 RCL+ .02
062 STO .02
063 RCL .00
064 x<>Y
065 MOD
066 x!=0?
067 RTN
068 RCL .00
069 RCL/ .02
070 STO .00
071 SQRT
072 IP
073 STO .01
074 INC .03
075 RCL .02
076 STO->.03
077 VWα+ .03
078 0
079 GTO 03

080 LBL 09
081 1
082 STO .04

083 LBL 10
084 CLα
085 α'⇕FC'
086 α'TR '
087 αRC# .04

088 LBL 11
089 VWα+->.04
090 PSE 99
091 KEY? .05
092 GTO 11
093 5
094 1
095 x=? .05
096 INC .04
097 6
098 1
099 x=? .05
100 DEC .04
101 RCL .04
102 x<1?
103 1
104 x>? .03
105 RCL .03
106 STO .04
107 GTO 10
108 LBL 99
109 CLα
110 α'BAD'
111 α' IN'
112 α'PUT'
113 VWα+ X
114 RTN

115 END

LBL 'FAC', LBL 01, and LBL 03 are all just the standard prime factoring routine. LBL 09 sets up the result viewer, LBL 10 displays the currently selected result, and LBL 11 handles the keyboard for viewing other results.

CAUTION: The factors are stored in global registers starting with 01, and going up to as many as are necessary to hold all factors. This is to allow for use of the interactive factor viewer.

Suggestions and improvements are welcome. This is my first crack at a WP-34S program.
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
(34S) Prime Factors - Dave Britten - 05-30-2014 01:53 AM
RE: (WP-34S) Prime Factors - Thomas Klemm - 05-30-2014, 03:30 AM
RE: (WP-34S) Prime Factors - Dave Britten - 05-30-2014, 03:54 AM
RE: (WP-34S) Prime Factors - Thomas Klemm - 05-30-2014, 08:24 AM
RE: (WP-34S) Prime Factors - Thomas Klemm - 05-30-2014, 07:06 PM
RE: (WP-34S) Prime Factors - Dave Britten - 05-30-2014, 08:07 PM
RE: (WP-34S) Prime Factors - Thomas Klemm - 05-30-2014, 08:58 PM
RE: (WP-34S) Prime Factors - Dave Britten - 05-30-2014, 09:42 PM
RE: (WP-34S) Prime Factors - Thomas Klemm - 05-30-2014, 10:57 PM
RE: (WP-34S) Prime Factors - Dave Britten - 05-30-2014, 11:58 PM
RE: (WP-34S) Prime Factors - Dave Britten - 05-31-2014, 01:09 AM
RE: (WP-34S) Prime Factors - Dave Britten - 06-01-2014, 06:11 PM



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