Skip to content

Instantly share code, notes, and snippets.

@ceaksan
Created March 9, 2018 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ceaksan/5ae89b3edb9acc0c0ef2af6def39714e to your computer and use it in GitHub Desktop.
Save ceaksan/5ae89b3edb9acc0c0ef2af6def39714e to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
)
func fibonacci(n int, c chan int) {
x, y := 0, 1
for i := 0; i < n; i++ {
c <- x
x, y = y, x+y
}
close(c)
}
func main() {
c := make(chan int, 10)
go fibonacci(cap(c), c)
for i := range c {
fmt.Println(i)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment