44999623da
since I was in here looking at something unrelated...
40 lines
701 B
Go
40 lines
701 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"strconv"
|
|
)
|
|
|
|
func fibonacci(c, quit chan int) {
|
|
x, y := 0, 1
|
|
for {
|
|
select {
|
|
case c <- x:
|
|
x, y = y, x + y
|
|
case <- quit:
|
|
return
|
|
}
|
|
}
|
|
}
|
|
|
|
func main() {
|
|
count := 10
|
|
if len(os.Args) > 1 {
|
|
var err error
|
|
if count, err = strconv.Atoi(os.Args[1]); err != nil {
|
|
fmt.Fprintln(os.Stderr, os.Args[1], "is not an int!")
|
|
os.Exit(1)
|
|
}
|
|
}
|
|
c := make(chan int)
|
|
quit := make(chan int)
|
|
go func(count int) {
|
|
for i := 0; i < count; i++ {
|
|
fmt.Println(<-c)
|
|
}
|
|
quit <- 0
|
|
}(count)
|
|
fibonacci(c, quit)
|
|
}
|