Jump to
Press alt + / to open this menu
Join or Log Into Facebook  
Do you want to join Facebook?
Sign Up

fun with HP-15C

Unless you have a time machine and a need to factorize numbers, this is going to be pretty useless...

lbl A

                sto 0           // reg 0 = x

                enter

                enter

                enter

                // we are going to count from 2 to sqrt(x), so

                // counter="2.sss01", where sss is sqrt(x)

                sqrt

                int

                // at this point, stack=s x x x

                0.01

                +

                1000

                /

                2

                +

                sto 1           // reg 1 = i

                // at this point, stack=. x x x

lbl 0

                clrx

                load 1

                int

                // stack=i x x x

                div

                frac

                test x=0

                goto 1          // we have a divider!

                isg reg1

                goto 0

                // we are done, x is now a prime

                roll down       // x x x .

                r/s

                1

                ret

 

lbl 1

                // last_x contains the future value of x (nx)

                last_x

                // at this point, stack = nx x x x

                load 1

                int             // i nx x x

                // display i to the user

                r/s

                roll down         // nx x x i

                // this is going to be inefficient, but works:

                // just start over

                goto A