Skip to content

Instantly share code, notes, and snippets.

@KamilaBorowska
Created August 4, 2015 11:23
Show Gist options
  • Save KamilaBorowska/80a4106cb55914eb113c to your computer and use it in GitHub Desktop.
Save KamilaBorowska/80a4106cb55914eb113c 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)
go fibonacci(42, 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