最近比较闲,想学一个新玩意,只是随便玩玩。。
1
artandlol 2018-09-25 15:45:05 +08:00
找素数的规律
package main import ( "fmt" "strconv" ) func main() { sieve() } func generate(ch chan<- int) { for i := 2; ; i++ { ch <- i } } func filter(src <-chan int, dst chan<- int, prime int) { str := "" for i := 0; i < prime; i++ { str += " " } for i := range src { if i%prime != 0 { dst <- i } } } func sieve() { ch := make(chan int) go generate(ch) var olddouble,diff,doubleprime int var count float64 for i := 0; i < 100; i++ { prime := <-ch doubleprime = prime*prime diff = doubleprime - olddouble strdiff := strconv.FormatInt(int64(diff), 10) floatdiff,err := strconv.ParseFloat(strdiff, 64) if err != nil { fmt.Print("error!", "\n") } count = floatdiff / 24 olddouble = doubleprime fmt.Print(prime,count, "\n") ch1 := make(chan int) go filter(ch, ch1, prime) ch = ch1 } } |
2
loading 2018-09-25 15:47:18 +08:00
用它跑 php,给 php 写个更快的 runtime.
|
3
hahasong 2018-09-25 15:59:27 +08:00 via iPhone
素数的规律高斯已经给出公式了
|
4
linghutf 2018-09-25 16:23:55 +08:00
机器学习啊,写写那些算法的 Go 版本
|