Created
April 27, 2023 14:18
-
-
Save vxcute/a2b454d550cf2559fa21f3bc3408701a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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