# HP Forums

Full Version: Factoring Integer into Primes: HP 48GX
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

I have the HP41 PPC ROM which contains a routine for factoring any integer into its prime number factors. I am reverse engineering it to make it run on the HP48GX. But might someone already have done that. Anyone know?

Hi John,

I wrote a prime factor program for my HP67 some time ago. In addition to prime factors, it will give all the primes between two given numbers as well. I'd love to have it on my 48gx, but I'm not that adept at RPL programming. Let me know if you want me to post it.

Best regards, Hal

My HP 48SX came with a factoring prg 'built in', among several other prgs in VAR. It factors a 10 digit number in less than half a sec. It shows automatically how long time it takes.

Quote:
I am reverse engineering it to make it run on the HP48GX.

Joe Horn has done this already:

```
123456789 RT ->  123456789: { 3 3 3607 3803 }    25.82 seconds (HP-48GX)
5961027250 RT -> 5961027250: { 2 5 5 5 3011 7919} 21.95 seconds
%%HP: T(3)A(D)F(,);
DIR
pf
\<< DUP { } SWAP
DO NP ROT
OVER + ROT ROT /
DUP
UNTIL 1 ==
END DROP SWAP
\->TAG
\>>
NP
\<< DUP \v/ \-> s
\<< DUP
IF 2 MOD
THEN 3
WHILE
DUP2 MOD OVER s <
AND
REPEAT 2
+
END DUP s
IF >
THEN DROP
DUP
END
ELSE 2
END
\>>
\>>
RT
\<< TIME SWAP pf
TIME ROT HMS- HMS\->
3600 * SWAP
\>>
END
```

I've written a List-to-Algebraic routine that will change { 3 3 3607 3803 } to '3^2*3607*3803'.

Gerson.

Thank you Gerson,

I'll key this into my 48gx and try it out.

Best regards, hal

I'm trying to key in and run this program, which Gerson Barbosa was kind enough to post, and have a couple of questions.

1. What are all the backslashes? I can't find that character listed in the 48G manual. I'm assuming the forward slashes denote division.

2. Could someone help me decipher this line " \<< DUP \v/ \-> s", in particular the backslashes, and the \v/?

My apologies for not being more RPL savvy, but I think I'm not alone in this boat:)

Best regards, hal

When you transfer special calculator characters they get automatically replaced by trigraphs (and back)

Edited: 21 Dec 2008, 1:15 a.m.

Thank you V-PN,

I see the light!! The program works beautifully now.

best regards, hal

V-PN has already been of help. Anyway, this is Joe Horn's program and documentation:

I've just found my L2A (list to algebraic) program, which I thought resided only in my HP-28S memory, here:

An even faster program is presented by Joe Horn himself in message #9, which I hadn't read yet. Thanks, Joe!

Regards,

Gerson.