HP 48SX prime factorizer routines, inspired by HP 41 PPC ROM's "NP": Name Description In Out +------+------------------------+--------+----+----------------+ | NP | Next Prime factor | n | -> | n factor | +------+------------------------+--------+----+----------------+ [#5AD9h, 122.5 w/ name] -- see pg. 627 for character translations. \<< 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 \>> \>> @ end of NP Name Description In Out +------+------------------------+--------+----+---------------------+ | PF | Prime Factors | n | -> | n: { factors of n } | +------+------------------------+--------+----+---------------------+ [#445Bh, 62 w/ name] \<< DUP { } SWAP DO NP ROT OVER + ROT ROT / DUP UNTIL 1 == END DROP SWAP \->TAG \>> @ end of PF To use NP, enter any integer n (greater than 0) and press NP. The original n will be raised to level 2, and the first prime factor of n will be placed in level 1. To find the next factor, you can press / and then run NP again. If you want to find all the prime factors of n, run PF. It replaces n with a list of its prime factors. Some sample PF times: 2 -> { 2 } in .09 sec 153 -> { 3 3 17 } in .33 sec 12345 -> { 3 5 823 } in .59 sec 1234567 -> { 127 9721 } in 2.47 sec 123456789 -> { 3 3 3607 3803 } in 40.19 sec Can the Saturn code in the HP 71 JPC Rom's "PRIM" be ported to the 48SX? Note to all you 48 experts: this is my first attempt at programming the 48, so forgive the inelegancies, like that horrible ROT OVER ROT ROT stuff. It seems to me that using STO and RCL for temporary storage slows a program down horribly, but elegant stack management is an art, not a science. If a way of improving these routines seems relatively intuitively obvious to you, post it, and help us BASIC spaghetti-coders learn "structured" programming... Thanx! Joseph K. Horn - 1042 Star Route - Orange, CA 92667 - (714) 858-0920