26 lines
433 B
Go
26 lines
433 B
Go
|
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
|
||
|
}
|