Browse Source

initial import of 1.02

master 1.02
Dan Ballard 11 years ago
commit
670e39d546
  1. 12
      ChangeLog
  2. 6
      Makefile
  3. 12
      README
  4. 693
      autoTest.pl
  5. 73
      languages
  6. 34
      primes.4.lua
  7. 32
      primes.5.lua
  8. 26
      primes.5c
  9. 4
      primes.R
  10. 44
      primes.adb
  11. 43
      primes.alt.c
  12. 42
      primes.alt2.c
  13. 49
      primes.alt3.c
  14. 28
      primes.awk
  15. 41
      primes.c
  16. 48
      primes.cbl
  17. 61
      primes.cpp
  18. 42
      primes.cs
  19. 61
      primes.e
  20. 23
      primes.erl
  21. 29
      primes.f
  22. BIN
      primes.fasl
  23. 36
      primes.fe
  24. 38
      primes.fs
  25. 17
      primes.hs
  26. 95
      primes.html
  27. 35
      primes.java
  28. 18
      primes.lisp
  29. 53
      primes.m
  30. 9
      primes.m4
  31. 31
      primes.ml
  32. 47
      primes.pas
  33. 31
      primes.perl.pl
  34. 25
      primes.php
  35. 38
      primes.pike
  36. 34
      primes.prolog.pl
  37. 27
      primes.py
  38. 28
      primes.r
  39. 36
      primes.rb
  40. 26
      primes.rexx
  41. 26
      primes.scm
  42. 42
      primes.sh
  43. 72
      primes.sieve.c
  44. 30
      primes.sml
  45. 29
      primes.st
  46. 29
      primes.tcl
  47. 31
      primes.vb
  48. 109
      primes.x86.s
  49. 28
      primes_prolog.pl
  50. BIN
      primesoc
  51. 45
      src/Main.m3
  52. 5
      src/m3makefile

12
ChangeLog

@ -0,0 +1,12 @@
1.2 (2011 03 08)
Poked autoTest.pl so lisp now runs on SBCL
Added imports to .cpp and .m so they compiled again
Other changes so things run on Ubuntu 10.04
1.1 (2004 10 08)
Added languages Smalltalk and Nickle and M4
Fixes for autotest.pl
Added README and ChangeLog
1.0 (2003 12 31)
Full release with 34 languages

6
Makefile

@ -0,0 +1,6 @@
default:
./autoTest.pl
clean:
rm -f *.txt primesc primescpp primesaltc primes.class primespas primes*.exe primes.o primesobjc primes.ali primesada primesfor primese primes.h primes1.c primes1.o primes.id primes.make primescbl link.res ppas.sh primes.beam primesocaml primesasm primes.cmi primes.cmx luac.out primeshs primes_clisp.fas primes.lib Main.hi primes_clisp.lib primes_clisp.o primes.hi primescsieve gst.im primesalt2c primesalt3c

12
README

@ -0,0 +1,12 @@
http://www.mindstab.net/tags/primes/
haplo@mindstab.net
Mindstab.net Multi language prime number project:
Prime number finders in ~38 languages
and a test driver
2011: Re-release
This project is still a terrible blunt way to see how different languages/implementation perform and compare at basic arithmatic and looping and crudly look at speed. And it's a small roseta stone too. Autotest.pl drives it all and it's appaling speghetti code I wrote half a decade ago and I probably still knew better. I've made a few quick updates since 1.01 from 2006 to make it run on Ubuntu 10.04 which is what I'm running. Your milage may vary, but it's on github now, so feel free to offer suggestions in code.
2004-2006
With this project I want to implement prime number finders in as many languages as I can. It's pretty much a way for me to learn a littlebit about a lot of languages. This project also comes with a test program (autoTest.pl) which can run and benchmark all the languages so I can see their various performances (part of learning about the languages).

693
autoTest.pl

@ -0,0 +1,693 @@
#!/usr/bin/env perl
# www.mindstab.net/primes
# Run prime number finders
# haplo@mindstab.net
print "Mindstab Development Multi-language Prime Number Project v1.02\n(www.mindstab.net/tag/primes/)\nhaplo\@mindstab.net\n\n";
# results file
$RESULTS="results.txt";
$TIME="time -p";
$os = `uname`;
$debug=0;
@langs = ("c",
# Uncomment for alternat C algorithms
# "c2", "ca", "ca2", "ca3",
"objc", "cpp", "asm", "for", "pas", "ada", "hs", "e", "cbl", "oml", "java", "cs", "vb", "erl", "awk", "pl", "php", "py", "tcl", "rb1.8", "rb1.9", "cl", "scm", "st", "sml", "4th", "pro", "m3", "pike", "lua", "rexx", "r", "fe", "5c", "m4", "sh");
$llen = $#langs+1;
print "Number of iterations to run tests [3]: ";
$itr = <stdin>;
chomp($itr);
print "\n";
if($itr < 1) { $itr = 3; }
print "Maximun number to search to [100000]: ";
$max = <stdin>;
chomp($max);
print "\n";
if($max < 1) { $max = 100000; }
#sources
$data{'c'}{'name'} = "C";
$data{'c'}{'src'}= "primes.c";
$data{'c'}{'prog'} = "primesc";
$data{'c'}{'compiler0'} = "gcc";
$data{'c'}{'cflags0'} = "-lm -O3 -o " . $data{'c'}{'prog'};
$data{'c2'}{'name'} = "C Sieve";
$data{'c2'}{'src'}= "primes.sieve.c";
$data{'c2'}{'prog'} = "primescsieve";
$data{'c2'}{'compiler0'} = "gcc";
$data{'c2'}{'cflags0'} = "-lm -O3 -o " . $data{'c2'}{'prog'};
$data{'ca'}{'name'} = "C Alternate Algorithm (Variable sqrt monitoring)";
$data{'ca'}{'src'}= "primes.alt.c";
$data{'ca'}{'prog'} = "primesaltc";
$data{'ca'}{'compiler0'} = "gcc";
$data{'ca'}{'cflags0'} = "-lm -O3 -o " . $data{'ca'}{'prog'};
$data{'ca2'}{'name'} = "C Alternate2 Algorithm (Variable sqrt monitoring and c math modulus)";
$data{'ca2'}{'src'}= "primes.alt2.c";
$data{'ca2'}{'prog'} = "primesalt2c";
$data{'ca2'}{'compiler0'} = "gcc";
$data{'ca2'}{'cflags0'} = "-lm -O3 -o " . $data{'ca2'}{'prog'};
$data{'ca3'}{'name'} = "C Alternate3 Algorithm (Variable sqrt monitoring and recursion)";
$data{'ca3'}{'src'}= "primes.alt3.c";
$data{'ca3'}{'prog'} = "primesalt3c";
$data{'ca3'}{'compiler0'} = "gcc";
$data{'ca3'}{'cflags0'} = "-lm -O3 -o " . $data{'ca3'}{'prog'};
$data{'asm'}{'name'} = "x86 Assembly";
$data{'asm'}{'src'} = "primes.x86.s";
$data{'asm'}{'prog'} = "primesasm";
$data{'asm'}{'compiler0'} = "gcc";
$data{'asm'}{'cflags0'} = "-O3 -o ". $data{'asm'}{'prog'};
$data{'asm'}{'pre'} = "echo \"$max\" | ";
$data{'asm'}{'osfilter'} = "OpenBSD";
$data{'objc'}{'name'} = "Objective C";
$data{'objc'}{'src'}= "primes.m";
$data{'objc'}{'compiler0'} = "gcc";
$data{'objc'}{'prog'} = "primesobjc";
$data{'objc'}{'cflags0'} = "-lobjc -lm -O3 -o " . $data{'objc'}{'prog'};
$data{'objc'}{'osfilter'} = "FreeBSD";
$data{'cpp'}{'name'} = "C++";
$data{'cpp'}{'src'}= "primes.cpp";
$data{'cpp'}{'compiler0'} = "g++";
$data{'cpp'}{'prog'} = "primescpp";
$data{'cpp'}{'cflags0'} = "-lm -O3 -o " . $data{'cpp'}{'prog'};
$data{'for'}{'name'} = "Fortran";
$data{'for'}{'src'} = "primes.f";
$data{'for'}{'compiler0'} = "g77";
$data{'for'}{'prog'} = "primesfor";
$data{'for'}{'cflags0'} = "-O3 -o $data{'for'}{'prog'}";
$data{'pas'}{'name'} = "Pascal";
$data{'pas'}{'src'} = "primes.pas";
$data{'pas'}{'compiler0'} = "fpc";
$data{'pas'}{'prog'} = "primespas";
$data{'pas'}{'cflags0'} = "-o$data{'pas'}{'prog'}";
$data{'ada'}{'name'} = "Ada";
$data{'ada'}{'src'} = "primes.adb";
$data{'ada'}{'compiler0'} = "gnatmake";
$data{'ada'}{'prog'} = "primesada";
$data{'ada'}{'cflags0'} = "-o $data{'ada'}{'prog'}";
$data{'ada'}{'cflagspre0'} = "rm -f primes.ali primes.o && ";
$data{'e'}{'name'} = "Eiffel";
$data{'e'}{'src'}= "primes.e";
$data{'e'}{'compiler0'} = "compile_to_c";
$data{'e'}{'prog'} = "primese";
$data{'e'}{'cflags0'} = "$data{'e'}{'src'} -boost -O3 -o " . $data{'e'}{'prog'}. " && sh primes.make";
$data{'e'}{'cflagspre0'} = "rm -f primes1.o && ";
$data{'awk'}{'name'} = "AWK";
$data{'awk'}{'src'} = "primes.awk";
$data{'awk'}{'pre0'} = "echo $max | ";
$data{'awk'}{'interp0'} = "awk";
$data{'awk'}{'iflags0'} = "-f " . $data{'awk'}{'src'};
$data{'sml'}{'name'} = "SML";
$data{'sml'}{'src'} = "primes.sml";
#$data{'sml'}{'iflagspre0'} = "echo primes $max | ";
$data{'sml'}{'iflagspre0'} = "cat $data{'sml'}{'src'} | sed -e 's/.*autotest.*/primes $max/' |";
$data{'sml'}{'interp0'} = "sml";
$data{'sml'}{'filter0'} = "sed -e '/[a-zA-Z\\-\\=]/g'";
$data{'m4'}{'name'} = "M4";
$data{'m4'}{'src'} = "primes.m4";
$data{'m4'}{'iflagspre0'} = "cat $data{'m4'}{'src'} | sed -e 's/.*autotest.*/PRIMES(3,$max,2,4)/' |";
$data{'m4'}{'interp0'} = "m4";
$data{'m4'}{'noarg'} = 1;
$data{'m4'}{'warn'} = "Execution is approximately 20-30 times slower than perl.";
$data{'m4'}{'reprompt'} = 1;
$data{'rexx'}{'name'} = "REXX";
$data{'rexx'}{'interp0'} = "rexx";
$data{'rexx'}{'prog'} = "primes.rexx";
$data{'r'}{'name'} = "REBOL";
$data{'r'}{'src'} = "primes.r";
$data{'r'}{'interp0'} = "rebol";
$data{'r'}{'iflags0'} = "--quiet $data{'r'}{'src'} $max";
$data{'oml'}{'name'} = "OCaml";
$data{'oml'}{'src'} = "primes.ml";
$data{'oml'}{'prog'} = "primesocaml";
$data{'oml'}{'compiler0'} = "ocamlopt";
$data{'oml'}{'cflags0'} = "-o $data{'oml'}{'prog'}";
$data{'oml'}{'cflagspre0'} = "rm -f primes.cmi primes.cmx && ";
$data{'erl'}{'name'} = "Erlang";
$data{'erl'}{'src'} = "primes.erl";
$data{'erl'}{'compiler0'} = "erlc";
$data{'erl'}{'interp0'} = "erl";
$data{'erl'}{'iflags0'} = "-noshell -s primes primes '$max'";
$data{'4th'}{'name'} = "Fourth";
$data{'4th'}{'src'} = "primes.fs";
$data{'4th'}{'interp0'} = "gforth-fast";
$data{'4th'}{'iflags0'} = "$data{'4th'}{'src'} -e '$max 2 4 primes bye'";
$data{'cbl'}{'name'} = "COBOL";
$data{'cbl'}{'src'} = "primes.cbl";
$data{'cbl'}{'prog'} = "primescbl";
$data{'cbl'}{'compiler'} = 2;
$data{'cbl'}{'compiler0'} = "cobc";
$data{'cbl'}{'cflags0'} = "-o $data{'cbl'}{'prog'} -O";
$data{'cbl'}{'compiler1'} = "htcobolpp";
$data{'cbl'}{'cflags1'} = "-o $data{'cbl'}{'prog'} -x ";
$data{'cbl'}{'pre'} = "echo \"$max\" | ";
$data{'cbl'}{'warn'} = "Execution is a slower than average, but nothing to worry about";
$data{'scm'}{'name'} = "Scheme";
$data{'scm'}{'src'} = "primes.scm";
$data{'scm'}{'interp'} = 3;
$data{'scm'}{'interp0'} = "scm";
$data{'scm'}{'iflags0'} = "-f ". $data{'scm'}{'src'}." -e \\\\\\\"(primes 3 $max)\\\\\\\"";
$data{'scm'}{'interp1'} = "mzscheme";
$data{'scm'}{'iflags1'} = "-m -f ". $data{'scm'}{'src'}." -e \\\\\\\"(and (primes 3 $max) (exit))\\\\\\\"";
$data{'scm'}{'interp2'} = "guile";
$data{'scm'}{'iflags2'} = "-l $data{'scm'}{'src'} -c '(primes 3 $max)'";
$data{'cl'}{'name'} = "Common Lisp";
$data{'cl'}{'src'} = "primes.lisp";
#$data{'cl'}{'compiler'} = 1;
#$data{'cl'}{'compiler0'} = "clisp";
#$data{'cl'}{'compiler0'} = "gcl";
#$data{'cl'}{'cflagspre0'} = "rm -f primes_clisp.lib primes_clisp.fas && ";
#$data{'cl'}{'cflagspre0'} = "rm -f primes2.o && ";
#$data{'cl'}{'cflags0'} = "-c";
#$data{'cl'}{'cflags0'} = "-compile";
$data{'cl'}{'interp'} = 1;#2
#$data{'cl'}{'interp0'} = "clisp";
#$data{'cl'}{'interp0'} = "gcl";
#$data{'cl'}{'iflags0'} = "-q -i primes2.fas -x '(primes $max)'";
#$data{'cl'}{'iflags0'} = "-load primes2.o -eval '(progn (primes $max) (bye))'";
$data{'cl'}{'interp0'} = "sbcl";
#$data{'cl'}{'interp0'} = "lisp";
$data{'cl'}{'iflags0'} = "--noinform --load primes.lisp --eval '(progn (primes $max) (quit))'";
#$data{'cl'}{'iflags0'} = "-quiet -load primes2.cl -eval '(progn (primes $max) (quit))'";
#"--noinform --load primes_clisp.cl --eval '(progn (primes $max) (quit))'";
$data{'cl'}{'filter0'} = "sed -e '/[;N]/g'";
#$data{'cl'}{'filter0'} = "sed -e '/[A-Z]/g'";
$data{'pro'}{'name'} = "Prolog";
$data{'pro'}{'src'} = "primes.prolog.pl";
$data{'pro'}{'interp'} = 2;
$data{'pro'}{'interp0'} = "pl";
$data{'pro'}{'iflagspre0'} = "echo '[primes_prolog]. primes($max).' | ";
$data{'pro'}{'iflags0'} = "-q";
$data{'pro'}{'filter0'} = "sed -e '/?/g'";
$data{'pro'}{'interp1'} = "gprolog";
$data{'pro'}{'iflags1'} = "--init-goal '[primes_prolog]' --entry-goal 'primes($max)' --query-goal 'halt(0)'";
$data{'pro'}{'iflagspre1'} = "export GLOBALSZ=40000; ";
$data{'pro'}{'filter1'} = "sed -e '/[?A-Za-z]/g'";
$data{'pl'}{'name'} = "PERL";
$data{'pl'}{'prog'} = "primes.perl.pl";
$data{'pl'}{'interp0'} = "perl";
$data{'5c'}{'name'} = "Nickle";
$data{'5c'}{'prog'} = "primes.5c";
$data{'5c'}{'interp0'} = "nickle";
$data{'5c'}{'warn'} = "Execution is approximately 20-30 times slower than perl.";
$data{'5c'}{'reprompt'} = 1;
$data{'st'}{'name'} = "Smalltalk";
$data{'st'}{'prog'} = "primes.st";
$data{'st'}{'interp0'} = "gst";
$data{'st'}{'iflags0'} = "-g $data{'st'}{'prog'} -a $max";
$data{'lua'}{'name'} = "Lua";
$data{'lua'}{'src'} = "primes.#VERSION#.lua";
#$data{'lua'}{'versionedsrc'} = 1;
$data{'lua'}{'versionfinder'} = "lua -v 2>&1 | awk '{print \$2}' | sed -e 's/[^54]//g'";
$data{'lua'}{'interp0'} = "lua";
$data{'lua'}{'iflagspre4'} = "echo $max | ";
$data{'pike'}{'name'} = "Pike";
$data{'pike'}{'prog'} = "primes.pike";
$data{'pike'}{'interp0'} = "pike";
$data{'m3'}{'name'} = "Modula-3";
$data{'m3'}{'compiler0'} = "m3build";
$data{'m3'}{'prog'} = "`ls */primesm3`";
$data{'tcl'}{'name'} = "TCL";
$data{'tcl'}{'src'} = "primes.tcl";
$data{'tcl'}{'interp'} = 2;
$data{'tcl'}{'interp0'} = "tclsh";
$data{'tcl'}{'iflags0'} = "$data{'tcl'}{'src'} $max";
$data{'tcl'}{'interp1'} = "tclsh8.3";
$data{'tcl'}{'iflags1'} = "$data{'tcl'}{'src'} $max";
$data{'tcl'}{'warn'} = "Execution is slower than average, but nothing to worry about";
$data{'sh'}{'name'} = "Shell";
$data{'sh'}{'prog'} = "primes.sh";
$data{'sh'}{'reprompt'} = 1;
$data{'sh'}{'interp0'} = "sh";
$data{'sh'}{'warn'} = "Execution is painfully slow.\n\t\t Do not try with numbers greater than a few thousand.";
$data{'hs'}{'name'} = "Haskell";
$data{'hs'}{'src'} = "primes.hs";
$data{'hs'}{'prog'} = "primeshs";
$data{'hs'}{'compiler'} = 2;
$data{'hs'}{'compiler0'} = "ghc";
$data{'hs'}{'cflags0'} = "-O -o $data{'hs'}{'prog'}";
$data{'hs'}{'filter0'} = "sed -e 's/\.\]/\ /g'";
$data{'hs'}{'cflagspre0'} = "rm -f Main.hi primes.o && ";
$data{'hs'}{'warn'} = "Compiler is slow";
$data{'hs'}{'compiler1'} = "interpB";
# Uncomment for Hugs, appears to be crazy slow or broken?
#$data{'hs'}{'interpB'} = "hugs";
#$data{'hs'}{'preB'} = "echo \'primes 3 $max 2 4\' | ";
#$data{'hs'}{'iflagsB'} = $data{'hs'}{'src'};
#$data{'hs'}{'filterB'} = "sed -e 's/\.\]/\ /g' | sed -e 's/Main>/\ /g' | sed -e '/[a-zA-Z\/]/g' | sed -e '/ /g' ";
#$data{'hs'}{'warnB'} = "Haskell compiler (ghc) not found.\nFalling back to Haskell interpreter (hugs).\nThis method is very slow!";
$data{'py'}{'name'} = "Python";
$data{'py'}{'prog'} = "primes.py";
$data{'py'}{'interp0'} = "python";
$data{'php'}{'name'} = "PHP";
$data{'php'}{'prog'} = "primes.php";
$data{'php'}{'interp0'} = "php";
$data{'fe'}{'name'} = "Ferite";
$data{'fe'}{'prog'} = "primes.fe";
$data{'fe'}{'interp0'} = "ferite";
$data{'fe'}{'pre0'} = "echo $max | ";
$data{'rb1.8'}{'name'} = "Ruby 1.8";
$data{'rb1.8'}{'prog'} = "primes.rb";
$data{'rb1.8'}{'interp0'} = "ruby1.8";
$data{'rb1.9'}{'name'} = "Ruby 1.9.1";
$data{'rb1.9'}{'prog'} = "primes.rb";
$data{'rb1.9'}{'interp0'} = "ruby1.9.1";
$data{'java'}{'name'} = "Java";
$data{'java'}{'src'} = "primes.java";
$data{'java'}{'compiler0'} = "javac";
$data{'java'}{'interp0'} = "java";
$data{'java'}{'prog'} = "primes";
$data{'java'}{'osfilter'} = "FreeBSD";
$data{'java'}{'osreprompt'} = "OpenBSD";
$data{'java'}{'oswarn'} = "OpenBSD";
$data{'java'}{'oswarnmsg'} = "This language has been flagged as unstable on this operating system";
$data{'cs'}{'name'} = "C# (Mono)";
$data{'cs'}{'src'} = "primes.cs";
$data{'cs'}{'compiler0'} = "mcs";
$data{'cs'}{'prog'} = "primescs.exe";
$data{'cs'}{'cflags0'} = "-o $data{'cs'}{'prog'}";
$data{'cs'}{'interp'} = 2;
$data{'cs'}{'interp0'} = "mono";
$data{'cs'}{'interp1'} = "mint";
$data{'vb'}{'name'} = "Visual Basic .Net (Mono)";
$data{'vb'}{'src'} = "primes.vb";
$data{'vb'}{'compiler0'} = "mbas";
$data{'vb'}{'prog'} = "primesvb.exe";
$data{'vb'}{'cflags0'} = "-o $data{'vb'}{'prog'}";
$data{'vb'}{'interp'} = 2;
$data{'vb'}{'interp0'} = "mono";
$data{'vb'}{'interp1'} = "mint";
$data{'vb'}{'osfilter'} = "FreeBSD";
sub checkValid
{
print "Checking outputed results for validity...\n";
local(@res) = `wc primes.*.txt`;
local($i);
for($i=0; $i < $#res; $i++)
{
$arr[$i][0] = `echo \"$res[$i]\" | awk '{print \$2}'`;
chomp($arr[$i][0]);
chomp($arr[$i][0]);
$arr[$i][1] = `echo \"$res[$i]\" | awk '{print \$4}'`;
chomp($arr[$i][1]);
chomp($arr[$i][1]);
}
# scan all others for differencees, for each match add 1 to [i][2]
$pt = 0;
for($i=0; $i<=$#arr; $i++)
{
$arr[$i][2] = 0;
for($p=0; $p <= $#arr; $p++)
{
if($p==$i) { next; }
if($arr[$i][0] == $arr[$p][0]) { $arr[$i][2]++; }
}
if($arr[$i][2] > $pt) {$pt = $arr[$i][2];}
}
print "Checked ". ($#arr+1)." ouput files of $execd executed languages for validity:\n";
if($pt != $#arr )
{
print "Differences detected in ".(($#arr+1)-($pt+1)) ." output files:\n";
for($i=0; $i<= $#arr; $i++)
{
if($arr[$i][2] < $pt || $pt == 0) {
print "\t". $arr[$i][1]."\n";
}
}
} else {
print "All output appears to be valid!\n";
}
print "View benchmark results in 'results.txt'\n";
}
sub parseTimes
{
if($debug) {
print "\n$cmd\n";
}
for($i=0; $i< $itr; $i++)
{
if($rcmd ne "") { `$rcmd`; }
my $tstr = `$cmd`;
print ".";
($tm[$i][0], $tm[$i][1], $tm[$i][2]) = $tstr =~
/[^\d]*(\d*\.\d*)[^\d]*(\d*\.\d*)[^\d]*(\d*\.\d*).*/;
}
my $tr = $tu = $ts =0.0;
for($i=0; $i< $itr; $i++)
{
$tr += $tm[$i][0];
$tu += $tm[$i][1];
$ts += $tm[$i][2];
}
$tr /= $itr;
$tu /= $itr;
$ts /= $itr;
$tr = substr($tr, 0,4);
$tu = substr($tu, 0,4);
$ts = substr($ts, 0,4);
#print results "$tr real\t$tu user\t$ts sys\n";
if(length($tr) == 1) { $tr .= "."; }
if(length($tr) == 2) { $tr .= "0"; }
if(length($tr) == 3) { $tr .= "0"; }
print results "$tr seconds\n";
}
sub getByLocate
{
local($where) = `locate $_[0] | grep bin | grep -v cgi | grep -v port | grep -v src`;
($where) = $where =~ /(.*\/$_[0])\n.*$/;
#print "WHERE: '$where'\n";
if($where eq "") { return ""; } else { return $where; }
}
sub getInterp
{
local($where) = `/usr/bin/whereis $_[0] | grep -v port`;
if(! ($where =~ "\:")) {
if($where eq "") { return getByLocate($_[0]); }
else { return "/usr/bin/env $_[0]";
}
} else
{
local($t1, $t2) = split(":", $where);
chomp($t2);
if($t2 ne "") {
return "/usr/bin/env $_[0]";
} else {
return getByLocate($_[0]);
}
}
}
# HEADER
open(results, ">".$RESULTS) || die("Cannot open $RESULTS\n");
print results "Prime number benchmarks\n";
$mach = `uname -a`;
print results "Benchmark machine: " . $mach."\n";
# TESTS
$yesall = 0;
$item = 0;
$execd = 0;
$compiler="";
foreach $l (@langs)
{
$item++;
$interpB = 0;
$compiler = "";
$version = "";
if($data{$l}{'osreprompt'} && $os =~ $data{$l}{'osreprompt'}) {
$data{$l}{'reprompt'} = 1;
}
if($data{$l}{'osreprompt'} && $os =~ $data{$l}{'oswarn'}) {
$data{$l}{'warn'} = $data{$l}{'oswarnmsg'};
}
if($yesall == 0 || $data{$l}{'reprompt'}){
print "($item/$llen) Run ".$data{$l}{"name"}." test\n";
if($data{$l}{'warn'} && !$data{$l}{"reprompt"}) { print "WARNING: $data{$l}{'warn'}\n";}
if($data{$l}{'reprompt'}) {
print "RE-PROMPT: WARNING: ";
if($data{$l}{"warn"}) {
print $data{$l}{'warn'};
} else {
print "Execution is excessively slow.";
}
print "\n";
}
print "(Y)es yes(A)ll (Q)uit [N]o : ";
$query = <stdin>;
$query = substr($query,0,1);
}
if($query eq "a" || $query eq "A")
{
$yesall = 1;
}
if(($yesall == 1 && !$data{$l}{'reprompt'}) || $query eq "y" || $query eq "Y" )
{
if($yesall == 1) {
if($query eq "n" || $query eq "N") { $query = "y";}
}
if($query eq "Y") {$query eq "y"; }
if($yesall == 1 && $query eq "y" && !$data{$l}{'reprompt'}) {
print "($item/$llen) ";
}
print "Testing ". $data{$l}{"name"}.":\n";
if($data{$l}{'warn'} && $yesall && $query eq "y") { print "WARNING: $data{$l}{'warn'}\n";}
if($query eq "A" || $query eq "a") {$query = "y";}
print results "($item/$llen) ". $data{$l}{"name"}." results:\n";
if( $data{$l}{'osfilter'} and $os =~ $data{$l}{'osfilter'})
{
print "ERROR: This language is flagged as incompatible with this operating system\n\n";
print results "ERROR: This language is flagged as incompatible with this operating system\n\n";
next;
}
$cmd="";
if( $data{$l}{"compiler0"})
{
print "Compiling";
print results "Compile";
if($l ne "java" && $l ne "m3") {$rcmd = "rm -f $data{$l}{'prog'}";}
else { $rcmd = "";}
$cmd .= "sh ";
if(!$debug) { $cmd .= "2>&1 "; }
$cmd .= "-c \"" .$TIME . " sh -c \\\"";
$cp = 0;
if(! $data{$l}{'compiler'})
{
$data{$l}{'compiler'} = 1;
}
for(; $cp < $data{$l}{'compiler'}; $cp++)
{
if($data{$l}{"compiler$cp"} eq "interpB")
{
$cp = $data{$l}{'compiler'};
$interpB = 1;
last;
}
$comp = getInterp($data{$l}{"compiler$cp"});
last if($comp ne "");
}
if($cp == $data{$l}{'compiler'}) {
$clist = "";
for($p=0;$p<$data{$l}{'compiler'};$p++)
{
last if($data{$l}{"compiler$p"} eq "interpB");
$clist .= "\t\t\t($p) ". $data{$l}{"compiler$p"}."\n";
}
print ":\tERROR - Unable to find one of the following compiler(s):\n$clist\n";
print results ":\tERROR - Unable to find one of the following compiler(s):\n$clist\n";
if(! $interpB) { next; }
}
if(!$interpB) {
$compiler = $data{$l}{"compiler$cp"};
print " [$compiler] ";
print results " [$compiler]:\t";
if(length($compiler) < 5) {print results "\t";}
if($data{$l}{"cflagspre$cp"}) { $cmd .= $data{$l}{"cflagspre$cp"};}
$cmd .= "$comp ";
if( $data{$l}{"cflags$cp"} )
{
$cmd .= $data{$l}{"cflags$cp"};
}
$cmd .= " ".$data{$l}{"src"}." ";
$cmd .= "\\\"\"";
#printf "CMD: '$cmd'\n";
parseTimes();
$rcmd = "";
print "\n";
}
}
if($interpB && $data{$l}{'warnB'})
{
print "WARNING: ".$data{$l}{'warnB'}."\n";
}
print "Executing";
print results "Execute";
$filter = "";
$interpreter = "";
$cmd = "sh ";
if(!$debug) { $cmd .= "2>&1 "; }
$cmd .= "-c \"". $TIME . " sh -c \\\"";
if( $data{$l}{"interp0"} or $interpB)
{
$ip=0;
if(! $data{$l}{'interp'}) {
$data{$l}{'interp'} = 1;
}
if($interpB) {
$interp = getInterp($data{$l}{'interpB'});
if($interp eq "") {
$ip = $data{$l}{'interp'};
} else {
$ip = "B";
}
}
else {
for(; $ip < $data{$l}{'interp'}; $ip++)
{
$interp = getInterp($data{$l}{"interp$ip"});
last if($interp ne "");
}
}
if($ip == $data{$l}{'interp'})
{
$ilist = "";
if($interpB) {
$ilist = "\t".$data{$l}{'interpB'}."\n";
} else
{
for($p=0;$p<$data{$l}{'interp'};$p++)
{
$ilist .= "\t\t\t($p) " .$data{$l}{"interp$p"}."\n";
}
}
print ":\tERROR - Unable to find one of the following interpreter(s):\n$ilist\n";
print results ":\tERROR - Unable to find one of the following interpreter(s):\n$ilist\n";
next;
}
$interpreter = $data{$l}{"interp$ip"};
print " [$interpreter]";
print results " [$interpreter]";
$filter = $data{$l}{"filter$ip"};
$cmd .= $data{$l}{"pre$ip"};
$cmd .= $data{$l}{"iflagspre$ip"};
$cmd .= "$interp ";
if(!$data{$l}{'noarg'})
{
if( $data{$l}{"iflags$ip"})
{
$cmd .= $data{$l}{"iflags$ip"}. " ";
} elsif( $data{$l}{"prog"} )
{
$cmd .= $data{$l}{"prog"}." $max ";
} else
{
if($data{$l}{"versionfinder"}) {
$version = `$data{$l}{"versionfinder"}`;
chomp($version);
$data{$l}{'src'} =~ s/#VERSION#/$version/;
}
if($version) {
if($data{$l}{"iflagspre$version"})
{
$cmd = $data{$l}{"iflagspre$version"} . $cmd;
}
}
$cmd .= $data{$l}{"src"}. " ";
$cmd .= "$max ";
}
}
} else
{
if($data{$l}{'pre'}) { $cmd .= $data{$l}{'pre'};}
$cmd .= "./" . $data{$l}{"prog"} . " $max";
$filter = $data{$l}{"filter$cp"};
}
if($filter) { $cmd .= " | $filter "; }
$cmd .= " > primes.$l.txt";
$cmd .= "\\\"\"";
print " ";
print results ":\t";
if(length($interpreter) < 5) { print results "\t";}
parseTimes();
print "\n";
print results "\n";
sleep 1;
$execd++;
}
elsif( $query eq "q" || $query eq "Q")
{
print "\n";
checkValid();
print "Quiting\n";
close(results);
exit;
}
print "\n";
}
checkValid();
close(results);

73
languages

@ -0,0 +1,73 @@
LANGUAGES
* = implemented
$ = implemented but no interpreter compatible with autotest
Rankings from freashmeat late 2003
number = number of projects on freshmeat.net (my crude ranking)
C * 5631
PERL * 2802
C++ * 2545
Java * 2473
PHP * 2122
Python * 1235
Unix Shell * 565
TCL * 360
JavaScript $ 253
Assmembly * 179
Objctive C * 142
Ruby * 133
Lisp+CLisp * 98
Pascal+Delphi * 88
Scheme * 80
C# * 47
Fortran * 47
Ada * 44
Awk * 42
VBasic+Basic * 32
Haskell * 30
ML * 26
caml/OCaml * 23
SmallTalk * 21
Eiffel * 21
Forth * 17
Erlang * 11
Prolog * 8
Cobol *
Modula *
Pike *
Rexx *
lua *
REBOL *
Ferite *
APL? 3
Rankings from http://merd.net/pixel/language-study
Statistics on usenet 1999 and 2000 in 3 graphs
java *
c++ *
c *
perl *
basic *
python *
javascript *
tcl *
ruby *
pascal *
ruby *
lisp *
ada *
smalltalk *
cobol *
fortran *
forth *
scheme *
eiffel *
prolog *
ml *

34
primes.4.lua

@ -0,0 +1,34 @@
-- Lua 4 version of a Prime Number Finder
-- haplo@mindstab.net
function primes(max)
cnt = 3
while cnt <= max do
sq = sqrt(cnt)
isp = 1
i = 3
while i <= sq and isp ~= 0 do
isp = mod(cnt, i)
i = i+2
end
if isp ~= 0 then
print(cnt)
end
cnt = cnt + 2
end
end
--argc = table.getn(arg)
argc = read()
max = tonumber(argc)
if max < 1 then
print("Usage: echo [Max Num] | lua primes.lua")
else
if not max then
print("Invalid Max Num")
else
primes(max)
end
end

32
primes.5.lua

@ -0,0 +1,32 @@
-- Lua 5 version of a Prime Number Finder
-- haplo@mindstab.net
function primes(max)
cnt = 3
while cnt <= max do
sq = math.sqrt(cnt)
isp = 1
i = 3
while i <= sq and isp ~= 0 do
isp = math.mod(cnt, i)
i = i+2
end
if isp ~= 0 then
print(cnt)
end
cnt = cnt + 2
end
end
argc = table.getn(arg)
if argc < 1 then
print("Usage: primeslua [Max Num]")
else
max = tonumber(arg[1])
if not max then
print("Invalid Max Num")
else
primes(max)
end
end

26
primes.5c

@ -0,0 +1,26 @@
#!/usr/bin/env nickle
# nickle version of a prime number finder
# haplo@mindstab.net
if (dim(argv) <= 1)
{
printf("Usage: primes.5c [Max]\n");
exit(1);
}
int max = atoi(argv[1]);
for ( int number = 3; number <= max; number += 2)
{
low_max = sqrt(number);
isPrime = true;
for ( int factor = 3; factor <= low_max; factor += 2)
{
if ( number % factor == 0)
{
isPrime = false;
break;
}
}
if (isPrime) printf("%d\n", number);
}

4
primes.R

@ -0,0 +1,4 @@
for ( number in 3:100 by 2) {
print (number)
number <- number + 1
}

44
primes.adb

@ -0,0 +1,44 @@
-- Ada version of a Prime Number Finder
-- Built with gnatmake 3.15p and gcc 3.2.3
-- haplo@mindstab.net
with Ada.Text_IO, Ada.Numerics.Elementary_Functions, Ada.Command_Line;
use Ada.Text_IO, Ada.Numerics.Elementary_Functions, Ada.Command_Line;
procedure primes is
package int_io is new integer_io(integer);
use int_io;
cnt, i, isPrime, test, MAX : integer;
begin
if argument_count >= 1 then
MAX := integer'value( argument(1) );
else
put_line("Useage: primesada [Max Num]");
return;
end if;
if MAX < 1 then
put_line("Max Num invalid");
return;
end if;
cnt := 3;
while cnt <= MAX loop
test := integer(sqrt(float(cnt)));
isPrime := 1;
i := 3;
while i <= test loop
if cnt mod i = 0 then
isPrime := 0;
exit;
end if;
i := i + 2;
end loop;
if isPrime /= 0 then
put(cnt, width=>0);
new_line(1);
end if;
cnt := cnt + 2;
end loop;
end primes;

43
primes.alt.c

@ -0,0 +1,43 @@
// C version of a Prime Number Finder
// Alternate Algorithm: Instead of using sqrt function,
// track it with two variables
// haplo@mindstab.net
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv)
{
unsigned int i, x, max=2, isP, sqr=4;
unsigned int MAX_NUM;
if(argc < 2) {
printf("primesaltc <MAX NUM>\n");
return -1;
} else {
MAX_NUM = atoi(argv[1]);
}
if(MAX_NUM < 1)
{
printf("Invalid MAX_NUM specified\n");
return -1;
}
for(i=3; i<=MAX_NUM; i+=2)
{
isP=1;
for(x = 3; x<=max; x+=2)
{
if( ! (i%x)){
isP=0;
break;
}
}
if(isP) printf("%d\n", i,max, sqr);
if(i>=sqr) {
max++;
sqr = max*max -2;
}
}
}

42
primes.alt2.c

@ -0,0 +1,42 @@
// C version of a Prime Number Finder
// Alternate Algorithm: Instead of using sqrt function,
// track it with two variables
// haplo@mindstab.net
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv)
{
unsigned int i, x, max=2, isP, sqr=4;
unsigned int MAX_NUM;
if(argc < 2) {
printf("primesaltc <MAX NUM>\n");
return -1;
} else {
MAX_NUM = atoi(argv[1]);
}
if(MAX_NUM < 1)
{
printf("Invalid MAX_NUM specified\n");
return -1;
}
for(i=3; i<=MAX_NUM; i+=2)
{
isP=1;
for(x = 3; x<=max; x+=2)
{
isP = i - (x* (i/x));
if(isP == 0) break;
}
if(isP) printf("%d\n", i,max, sqr);
if(i>=sqr) {
max++;
sqr = max*max -2;
}
}
}

49
primes.alt3.c

@ -0,0 +1,49 @@
// C version of a Prime Number Finder
// Alternate Algorithm: Instead of using sqrt function,
// track it with two variables
// haplo@mindstab.net
#include <stdio.h>
#include <stdlib.h>
int check(int i, int cnt, int m)
{
if(i > m) return 1;
else {
if( (cnt%i)==0) return 0;
return check(i+2,cnt, m);
}
}
int primes(int c, int m, int sq, int sqm)
{
if(c > m) return 1; else
{
if(check(3,c,sq))
printf("%d\n", c);
if(c>=sqm) {
sq++;
sqm = sq*sq;
}
return primes(c+2, m, sq, sqm);
}
}
int main(int argc, char **argv)
{
unsigned int i, x, max=2, isP, sqr=4;
unsigned int MAX_NUM;
if(argc < 2) {
printf("primesaltc <MAX NUM>\n");
return -1;
} else {
MAX_NUM = atoi(argv[1]);
}
if(MAX_NUM < 1)
{
printf("Invalid MAX_NUM specified\n");
return -1;
}
primes(3, MAX_NUM, 2,4);
}

28
primes.awk

@ -0,0 +1,28 @@
#!/usr/bin/awk -f
# AWK version of a Prime Number Finder
# haplo@mindstab.net
{ max = $1; }
END {
if(max < 1)
{
print "primes.awk <MAX NUM>"
} else
for (i=3; i < max ; i+=2)
{
maxT = sqrt(i)+1
isPrime = 1
for (p=3; p < maxT; p+=2)
{
isPrime = i % p
if( isPrime == 0)
{
break
}
}
if(isPrime != 0) {
print i
}
}
}

41
primes.c

@ -0,0 +1,41 @@
// C version of a Prime Number Finder
// haplo@mindstab.net
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
int main(int argc, char ** argv)
{
unsigned int counter, max_test, tester;
char isPrime;
unsigned int MAX_NUM;
if(argc < 2) {
printf("primesc <MAX NUM>\n");
return 1;
} else {
MAX_NUM = atoi(argv[1]);
}
if(MAX_NUM < 1)
{
printf("Invalid MAX_NUM specified\n");
return 1;
}
for(counter =3; counter<= MAX_NUM; counter +=2)
{
max_test = (int) sqrt((double) counter);
isPrime = 1;
for(tester =3; tester <= max_test; tester += 2)
{
if(! (counter % tester)) {
isPrime = 0;
break;
}
}
if(isPrime) printf("%d\n", counter);
}
return 0;
}

48
primes.cbl

@ -0,0 +1,48 @@
IDENTIFICATION DIVISION.
PROGRAM-ID. primes.
AUTHOR. Dan Ballard.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 Cnt PIC S9(10) VALUE 3.
01 TMax PIC S9(10) VALUE 3.
01 I PIC S9(10) VALUE 0.
01 isp PIC S9(10) VALUE 1.
01 tmp PIC S9(10) VALUE 1.
01 break PIC 9 VALUE 0.
01 MAX PIC S9(10) VALUE 20.
01 SQT PIC S9(10) VALUE 4.
01 SQ PIC S9(10) VALUE 2.
PROCEDURE DIVISION.
Main.
ACCEPT MAX
IF MAX < 1
DISPLAY "Invalid Max Num"
EXIT
END-IF
PERFORM UNTIL Cnt > MAX
MOVE 3 TO I
MOVE 0 TO break
MOVE 1 TO isp
PERFORM UNTIL I > SQ OR break = 1
MOVE Cnt TO isp
DIVIDE Cnt BY i GIVING tmp REMAINDER isp
IF isp = 0
MOVE 1 TO break
END-IF
ADD 2 TO I
END-PERFORM
IF NOT isp = 0
DISPLAY Cnt
END-IF
ADD 2 TO Cnt
IF Cnt > SQT
ADD 1 TO SQ
MULTIPLY SQ BY SQ GIVING SQT
END-IF
END-PERFORM
STOP RUN.

61
primes.cpp

@ -0,0 +1,61 @@
// C++ version of a Prime Number Finder
// haplo@mindstab.net
#include <iostream>
#include <math.h>
#include <string>
#include <stdlib.h>
using namespace std;
class CPrimes
{
public:
void countPrimes(unsigned int MAX);
};
void CPrimes::countPrimes(unsigned int MAX)
{
for(unsigned int cnt = 3; cnt <= MAX; cnt+=2)
{
int test = (int)sqrt((double)cnt);
char isPrime=1;
for(int i = 3; i<= test; i+=2)
{
if(! (cnt % i))
{
isPrime = 0;
break;
}
}
if(isPrime)
{
cout << cnt << endl;
}
}
}
int main(int argc, char **argv)
{
int MAX;
if(argc <= 1) {
cout << "Useage: primescpp [Max Num]" << endl;
return(1);
} else {
MAX = atoi(argv[1]);
}
if(MAX < 1) {
cout << "Invalide Max Num" << endl;
return(1);
}
CPrimes *primes = new CPrimes();
primes->countPrimes(MAX);
delete primes;
return(0);
}

42
primes.cs

@ -0,0 +1,42 @@
// C# version of a Prime Number Finder
// Build under Mono .28
// haplo@mindstab.net
using System;
class Primes {
private static void Main(String[] argv)
{
int MAX=0;
if(argv.Length >= 1) {
try {
MAX = (int)Convert.ToDouble(argv[0]);
} catch {
Console.WriteLine("Invalid Max Num");
return;
}
} else {
Console.WriteLine("Useage: primes.exe [Max Num]");
return;
}
for(int cnt = 3; cnt <= MAX; cnt+= 2)
{
int test = (int) Math.Sqrt(cnt);
int isPrime = 1;
for(int i=3; i <= test; i+=2)
{
isPrime = cnt % i;
if( isPrime == 0) {
break;
}
}
if(isPrime != 0)
{
Console.WriteLine(cnt);
}
}
}
}

61
primes.e

@ -0,0 +1,61 @@
-- Eiffel version of a Prime Number Finder
-- haplo@mindstab.net
-- Anyone know how to round off doubles? or cast them to integers please
-- email me. I should be able to speed this up then.
class PRIMES
creation make
feature
make is
local
max, i, cnt, isprime : INTEGER;
test: DOUBLE;
stop : BOOLEAN;
do
if argument_count < 1 or else not argument(1).is_integer then
io.put_string("Useage: primese [Max Num]%N");
die_with_code(exit_failure_code);
else
max := argument(1).to_integer;
end;
from
cnt := 3;
until
cnt > max
loop
test := cnt.sqrt;
isprime := 1;
stop := false;
from
i := 3;
until
i > test or stop
loop
from
isprime := cnt;
until
isprime < i
loop
isprime := isprime-i;
end;
--isprime := cnt - (i* do_round_down(cnt/i));
if isprime = 0 then
stop := true
end;
i := i + 2;
end;
if isprime /= 0 then
io.put_integer(cnt);
io.put_string("%N");
end;
cnt := cnt + 2;
end;
end;
end

23
primes.erl

@ -0,0 +1,23 @@
% Erlang version of a Prime Number Finder
% haplo@mindstab.net
-module(primes).
-author('haplo@mindstab.net').
-export([primes/1]).
check(I, Cnt, Max) when I < Max, (Cnt rem I) == 0 -> 0;
check(I, Cnt, Max) when I < Max -> check(I+2, Cnt, Max);
check(I, Cnt, Max) -> 1.
primes([Max]) -> primes(3, list_to_integer(atom_to_list(Max)), 2, 4);
primes(Max) -> primes(3, Max, 2, 4).
primes(Cnt, Max, Sq, Sqm) when Cnt < Max, Cnt >= Sqm ->
primes(Cnt, Max, Sq+1, (Sq+1)*(Sq+1));
primes(Cnt, Max, Sq, Sqm) when Cnt < Max ->
case check(3, Cnt, Sq) of
0 -> 0;
C -> io:format("~p\n", [Cnt])
end,
primes(Cnt+2, Max, Sq, Sqm)
;
primes(Cnt, Max, Sq, Sqm) -> init:stop().

29
primes.f

@ -0,0 +1,29 @@
c Fortran version of a Prime Number Finder
c haplo@mindstab.net
program primes
implicit none
real test, i;
integer isPrime, amax, cnt;
character *32 buff;
if (iargc() >= 1) then
call getarg(1, buff);
read(buff, *) amax;
else
print*, "Useage: primesf [Max Num]";
return
endif
do cnt = 3, amax, + 2
test = sqrt(float(cnt));
isPrime=1;
do test = 3, test, +2
if (mod(cnt, test) == 0) then
isPrime=0;
exit;
endif
enddo
if(isPrime /= 0) print*,cnt
c if(isPrime /= 0) write(*,'(I3.1)'),cnt
enddo
end

BIN
primes.fasl

Binary file not shown.

36
primes.fe

@ -0,0 +1,36 @@
#!/usr/bin/env ferite
/* Ferite version of a Prime Number Finder
* haplo@mindstab.net */
uses "array", "console", "math";
array fncArgs;
number MAX, cnt, test, i, remainder;
string foo;
MAX = 10;
foo = Console.readln();
foo = String.trim(foo, "\n");
if(String.isNumber(foo))
{
MAX = String.toNumber(foo);
} else {
Console.println("Useage: primes.fe [Max Num]\n");
}
if(MAX < 1) { Console.println("Invalid Max Num\n"); }
i = 0;
for(cnt = 3; cnt <= MAX; cnt +=2)
{
test = Math.sqrt(cnt);
remainder=1;
for(i=3; i<= test; i+=2)
{
remainder = cnt%i;
if(! remainder) break;
}
if(remainder)
Console.println(cnt);
}

38
primes.fs

@ -0,0 +1,38 @@
( Forth version of a Prime Number Finder
haplo@mindstab.net )
: check ( m cnt -- b )
{ m cnt }
\ var i
-1 3 -1
begin
over m <= and while
nip
dup 2 + swap cnt swap mod tuck ( # cnt+2 # )
repeat
drop
;
: primes ( m sq sqm -- )
{ m sq sqm }
\ var i sq sqm
sqm sq 3
begin
dup m <= while
over over \ sq(max) cnt
check ( max cnt -- b )
if dup . CR then
2 +
rot ( sq cnt sqm ) over over
> if
rot ( cnt sqm sq )
1 + nip ( cnt sq )
dup dup * ( cnt sq sqm )
rot swap ( sq cnt sqm )
then
\ sqm sq 3
rot rot
repeat
drop drop drop
;

17
primes.hs

@ -0,0 +1,17 @@
-- Haskell version of a Prime Number Finder
-- haplo@mindstab.net
import System
check i c m | i > m = [(show c) ++ " "]
| rem c i > 0 = check (i+2) c m
| otherwise = []
primes c m s t | c < m && c >= t = primes c m (s+1) ((s+1)*(s+1))
| c < m = check 3 c s ++ primes (c+2) m s t
| otherwise = []
main = do
x <- getArgs
print (primes 3 (read (x!!0)::Int) 2 4)

95
primes.html

@ -0,0 +1,95 @@
<html>
<head>
<script language="JavaScript">
<!--
function primes(form)
{
today = new Date();
sec = today.getTime();
max = form.max.value;
form.txt.value="";
for(cnt=3; cnt<= max;cnt+=2)
{
sq = Math.round(Math.sqrt(cnt));
isprime = true;
for(i=3; i<=sq; i+=2)
{
if(cnt % i == 0)
{
isprime = false;
break;
}
}