23 lines
276 B
Go
23 lines
276 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
)
|
|
|
|
func fibonacci(n int, c chan uint64) {
|
|
var x, y uint64 = 0, 1
|
|
for i := 0; i < n; i++ {
|
|
c <- x
|
|
x, y = y, x+y
|
|
}
|
|
close(c)
|
|
}
|
|
|
|
func main() {
|
|
fc := make(chan uint64, 80)
|
|
go fibonacci(cap(fc), fc)
|
|
for i := range fc {
|
|
fmt.Println(i)
|
|
}
|
|
}
|