Skip to content

Instantly share code, notes, and snippets.

@cuixin
Last active December 23, 2015 07:09
Show Gist options
  • Select an option

  • Save cuixin/6599266 to your computer and use it in GitHub Desktop.

Select an option

Save cuixin/6599266 to your computer and use it in GitHub Desktop.
fibonacci implements by go, and used closure.
package main
import (
"fmt"
)
func fib(i, j int) func() int {
return func() int {
i, j = j, i+j
return j
}
}
func main() {
f := fib(0, 1)
for i := 0; i < 20; i++ {
fmt.Println(f())
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment