exercism/go/sieve/sieve.go

26 lines
433 B
Go
Raw Normal View History

2016-08-13 23:20:14 +00:00
package sieve
import "fmt"
// Sieve applies the Sieve of Eratosthenes up to depth
// Returning a slice of all of the results
func Sieve(depth int) []int {
var primes []int
test := 2
for test <= depth {
testIsPrime := true
for idx := range primes {
if test%primes[idx] == 0 {
testIsPrime = false
break
}
}
if testIsPrime {
primes = append(primes, test)
}
test++
fmt.Println("")
}
return primes
}