Sieve of Eratosthenes

by Tom Cone (tcone@ix.netcom.com)

Prime numbers are integers greater than one, that are evenly divisible only by themselves and one. The 'Sieve of Eratosthenes' is named after an ancient Greek mathematician who developed one of the best ways to identify prime numbers. It is still in current use as a benchmark for measuring the speed at which new computers can crunch integers. There are other approaches that can be taken to identify prime numbers. Some are faster. However, this one is easily understood and is unique in that it accomplishes its feat without division.

Recently I decided to implement the 'Sieve' in Xbasic, using Alpha Five. This was done in part just to see if it could in fact be done, and in part to see how quickly (or slowly) Alpha Five would perform. I was pleasantly surprised with the results.

The downloadable zip file contains an Alpha Five database called 'Primes'. It should be unzipped to its own (separate) folder. There is just one table in the database, and it contains no records. There are no forms or reports, just one script which is found under the Code Tab in the Control Panel. It's called 'Sieve'. When the script is run all the prime numbers from 2 to 1000 are calculated and written to the trace window. The code is heavily commented so you might take a few minutes and study it. While there's nothing much original or creative there, it is a good example of the power of nested loops within a script.

8/23/00

Don't forget, we need your feedback to make this site better!

Return to home