daily pastebin goal
11%
SHARE
TWEET

Untitled

a guest Jun 6th, 2018 54 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package main
  2.  
  3. import (
  4.     "fmt"
  5.     "math"
  6.     "time"
  7. )
  8.  
  9. var list = make([]int, 0, 1)
  10.  
  11. func checkPrime(numero int) {
  12.     var lim = (int)(math.Floor(math.Sqrt(float64(numero))) + 1)
  13.  
  14.     for j := 0; j < len(list); j++ {
  15.         if numero%list[j] == 0 {
  16.             return
  17.         }
  18.         if list[j] > lim {
  19.             break
  20.         }
  21.     }
  22.         list = append(list,numero)
  23. }
  24.  
  25. func getPrimes(upperLimit int) {
  26.     for i := 3; i < upperLimit; i += 2 {
  27.         checkPrime(i)
  28.     }
  29. }
  30.  
  31. func main() {
  32.     benchmakFunction(func() {
  33.         getPrimes(67108864)
  34.     })
  35.     fmt.Println(len(list),list[len(list)-1])
  36. }
  37.  
  38. func benchmakFunction(functionToBench func()) {
  39.     list = append(list,2)
  40.     fmt.Println(time.Now())
  41.     functionToBench()
  42.     fmt.Println(time.Now())
  43. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top