Skip to content

Instantly share code, notes, and snippets.

@vxcute
Created April 27, 2023 14:18
Show Gist options
  • Save vxcute/a2b454d550cf2559fa21f3bc3408701a to your computer and use it in GitHub Desktop.
Save vxcute/a2b454d550cf2559fa21f3bc3408701a to your computer and use it in GitHub Desktop.
// high performant concurrent fibonacci numbers generator
package main
import (
"fmt"
"math/big"
)
func fib() chan string {
c := make(chan string, 1)
go func() {
a, _ := new(big.Int).SetString("1", 10)
b, _ := new(big.Int).SetString("2", 10)
for {
c <- a.String()
a, b = b, a.Add(a, b)
}
}()
return c
}
func main() {
c := fib()
for n := range c {
fmt.Println(n)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment