BASIC Programming |
On a Graphing Calculator |
I got my Graphing calculator in Grade 9, and as soon as I found out I could write programs on it,
I spent late nights playing with code. At first it seemed like a portable Atari 400, which I used
for a few years before accidentally fying in the dark. (More on that on my Atari Page)
Some of my earliest programs for the calculator were made to speed up math class. In one unit we were asked
to figure out whether or not a number was prime, so I made a program that did just that.
Prime Number Calculator |
Grade 9 Math |
Grade 9 math was all about dividing something into it's prime numbers. Prime factorization, they called it.
I didn't want to bother doing that much work, and I was curious, so I went ahead and used my calculator to
do it for me. The program, as written in Mr. Beazer's class, is shown below:
ClrHomestartTmrDisp “ENTER A NUMBER“Prompt PcheckTmr(0)->Tint(P)->XIf P!=XGoto 3If P=1 or P<=1Goto 2For(X,2,P-1) P/X->D Disp D D->O int(O)->O If D=O Goto 1 If sqrt(P)<X Goto 4EndLbl 4Disp ““Disp PDisp “ IS PRIME“Disp ““Disp “CALCULATED IN“Disp checkTmr(0)-TDisp “ SECOND(S)“StopLbl 2Disp “INT<=1 NOT PRIME“StopLbl 3Disp “DEC. NOT PRIME“StopLbl 1Disp ““,P,“/“,D,P/DDisp “NOT PRIME“Stop
I start by asking for a number, then dividing that number by every whole number up to itself. If every whole
number divided to a rational number, then it could be said the number is prime. Then I realized
I could double the speed of this process by only counting to half the given number. This makes sense, because
dividing by a number less than half the dividend gives a quotient more than half the dividend. (12 / 2 = 6, so
there's no point in checking 12 / 6 = 2)
The program optimized, I began sharing it with friends through a cable, and tapping it out on the old calculators
that were incompatible with my newer color screen calculator.