Skip to content

Instantly share code, notes, and snippets.

@tgross tgross/primes.go
Created Nov 22, 2019

Embed
What would you like to do?
Dummy application for testing Nomad batch workloads
package main
import (
"fmt"
"os"
"strconv"
)
// return list of primes less than N
func sieveOfEratosthenes(N int) (primes []int) {
b := make([]bool, N)
for i := 2; i < N; i++ {
if b[i] == true {
continue
}
primes = append(primes, i)
for k := i * i; k < N; k += i {
b[k] = true
}
}
return
}
func main() {
arg := os.Args[1]
n, _ := strconv.Atoi(arg)
primes := sieveOfEratosthenes(n)
for _, p := range primes {
fmt.Println(p)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.