adding go
This commit is contained in:
parent
a61265e2ed
commit
6dc292bc10
2
Makefile
2
Makefile
|
@ -3,4 +3,4 @@ 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
|
||||
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 primesgo
|
||||
|
|
4
README
4
README
|
@ -2,9 +2,11 @@ http://www.mindstab.net/tag/primes/
|
|||
haplo@mindstab.net
|
||||
|
||||
Mindstab.net Multi language prime number project:
|
||||
Prime number finders in ~39 languages
|
||||
Prime number finders in ~40 languages
|
||||
and a test driver
|
||||
|
||||
2014: added go
|
||||
|
||||
2013: Cleanedup and small additions
|
||||
Cleaned up code to work with newer versions of compilers and interpreters and added a few new languages
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ $debug=0;
|
|||
@langs = ("c",
|
||||
# Uncomment for alternat C algorithms
|
||||
# "c2", "ca", "ca2", "ca3",
|
||||
"objc", "cpp", "asm", "for", "pas", "ada", "hs", "e", "cbl", "oml", "java", "scala", "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");
|
||||
"objc", "cpp", "asm", "for", "pas", "go", "ada", "hs", "e", "cbl", "oml", "java", "scala", "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;
|
||||
|
||||
|
@ -117,6 +117,12 @@ $data{'awk'}{'pre0'} = "echo $max | ";
|
|||
$data{'awk'}{'interp0'} = "awk";
|
||||
$data{'awk'}{'iflags0'} = "-f " . $data{'awk'}{'src'};
|
||||
|
||||
$data{'go'}{'name'} = "Go";
|
||||
$data{'go'}{'src'} = "primes.go";
|
||||
$data{'go'}{'compiler0'} = 'go';
|
||||
$data{'go'}{'cflags0'} = 'build -o primesgo ';
|
||||
$data{'go'}{'prog'} = 'primesgo';
|
||||
|
||||
$data{'sml'}{'name'} = "SML";
|
||||
$data{'sml'}{'src'} = "primes.sml";
|
||||
#$data{'sml'}{'iflagspre0'} = "echo primes $max | ";
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
package main
|
||||
|
||||
// Go version of a prime number finder
|
||||
|
||||
import(
|
||||
"fmt"
|
||||
"os"
|
||||
"strconv"
|
||||
"math"
|
||||
)
|
||||
|
||||
func main() {
|
||||
if len(os.Args) < 2 {
|
||||
fmt.Println("Usage: go run primes.go [MAX]")
|
||||
return
|
||||
}
|
||||
max,_ := strconv.Atoi(os.Args[1])
|
||||
for i:= 3; i < max; i+=2 {
|
||||
is_prime := true
|
||||
for j := 3; j <= int(math.Ceil(math.Sqrt(float64(i)))); j+=2 {
|
||||
if i % j == 0 {
|
||||
is_prime = false
|
||||
break
|
||||
}
|
||||
}
|
||||
if is_prime {
|
||||
fmt.Println(i)
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue