Skip to content

Instantly share code, notes, and snippets.

@paulobsf
Created November 1, 2015 10:52
Show Gist options
  • Save paulobsf/995481f45fc925cb697a to your computer and use it in GitHub Desktop.
Save paulobsf/995481f45fc925cb697a to your computer and use it in GitHub Desktop.
Go-Routine Fibonacci sequence
// from: http://jbu.io/2015/10/28/six-reasons-why-i-love-go/
package main
import "fmt"
func fibonacci() chan int {
c := make(chan int)
go func() {
for i, j := 0, 1; ; i, j = i+j,i {
c <- i
}
}()
return c
}
func main() {
c := fibonacci()
for n := 0; n < 12 ; n++ {
fmt.Printf("%d ", <- c)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment