At the moment, this archive consists of programs written in many different programming languages. In particular, we are featuring The Sieve of Eratosthenes written in several different languages. All of these programs have been compiled and run.
If you would like to contribute code to this archive, feel free. E-Mail me the code with a printout of the result. Things I am interested in are implementations of the following algorithm in languages other than those posted here, and collections of other algorithms, preferably the same algorithm implemented in several different languages.
The algorithm is as follows.
1. Initialize an array indexed from 0 to 999 with all 1's (You may change the 0 to a 1 or the 999 to 1000 if necessary.)
2. The indices of the array correspond to the integers, with 1's indicating the positions of the primes and 0's indicating the positions of the composites.
3. Cross out 0 and 1, since they are not prime.
4. Repeatedly do the following.
5. Find the first unprocessed number p that isn't crossed out. The number p must be prime.
6. Cross out all multiples of the prime p, starting with 2*p.
7. Terminate the repetition when the index position exceeds 999.
8. Print the un-crossed-out numbers.
This algorithm provides assignments, If statements and WHILE and FOR loops, but is not sufficient to distinguish the various C-type languages from one another. Thus C, C++, Java, and C# all look the same. Eventually I hope to add a binary search tree program to show differences between object-oriented languages.
I realize that it is possible to clean up this algorithm and make it much more elegant. I don't want to do that, because the current implementation illustrates the basic language structures better than a more elegant algorithm. (The cleaned-up version has no while loops or compound contitions.)
Here are the implementation languages. Click on the name of the language to
see the code.
Algol 60 for the IBM 360
APL and J
BAL: IBM Assembly Language
Basic (Original dialect)
Intel i386 Assembler (GNU version)
Pascal (which includes Delphi)
We need implementations in the following languages,
assuming, of course, that this is possible. All examples need to compile
and run correctly. If you want to contribute, remember that it is necessary
to reproduce my algorthm without cleaning it up, and it is necessary that your
code compile and run correctly. Send me proof of this along with the code.
assembler (Especially x86, PDP-11, VAX, Motorola 68X, SPARC, MIPS, and MIXAL)
anything else you can think of.