program project started in the fall of 2000, and not completed until late spring 2001. The project was to make a Casio program capable of telling prime numbers
apart from ordinary numbers. We knew it already excisted, as it came with the calculator
, but we still wanted to figure out how to do it. My team consisted of myself, and two other creme de la creme Casio programmers; Codepie
, and Teh Confuz0r (1337
The theory behind telling a prime number from an ordinary number in a simple Basic
program with limited functions, was cracked out as joint
venture between the three of us, and is as follows:
Everybody knows that prime numbers can only be divided by 1 and itself. So what we needed to do was to try to divide the number in question with all the integer
values between 2 and the value that was the number itself divided by 2. Why "the value that was the number itself divided by 2"? It isn't necessary but it cuts the computing time in half when the number in question really is a prime number. Let me demonstrate why:
No higher values of the divisor will render a number that is =>2
, thus it is not necessary to do these calculations.
All this was easy, the problems came when we had to find out if the quotient
had any decimals in it. This is done by multiplying the integer value of the quotient with the divisor
. If the product equals the dividend
, the quotient has no decimals in it.
So if a given number is divided by all integer values between 2 and half of the number in question, and all of the calculations show up having decimals, we know that the number is prime. And if one or more of the calculations show up without decimals, the number is not prime, logically enough :)
So far we are still in the autumn, 2000. It was when we where ready to move off the paper, and onto the 64KB monster
of a machine, that new problems arrived. We could not find a way to change between systems of notation mid-program. We needed to go from normal (Floating point
), to integer, and back to normal, for each calculation. The answer didn't present itself until the spring of 2001. During a German class, I was goofing around, and found a very simple function allowing one to define what system of notation to use. In retrospect
I realize that I could just have used a similar function to extract the values behind the comma, and check if it was larger than 0. Well, well...
On to the source already:
with the 9X50 range of Casio calculators
, maybe others aswell.)
All text not within "" are functions
, and should not be typed, rather than found within some submenu.
All lines end with a "next-line-bent-arrow-thingie" (Looks like your return
button.), except for those that end with a »
. In place of these should a "stop-and-wait-for-exe-thingie" be put. (Looks like a triangle
pointing down, and to the right)
is the "save as" button.
Then "IS PRIME:"
"ONLY DIVIDIBLE BY:"
"1 AND SELF" »
If Intg C×B=A
"IS NOT PRIME:"
"DIVIDIBLE BY, AND"
Else Isz B
Of course all text is editable. My observations
show that this program is far more optimized than the one that comes with the calculator.