Skip to content

Instantly share code, notes, and snippets.

@oldergod
Last active August 29, 2015 14:06
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 oldergod/1d0408a5833e1d44640c to your computer and use it in GitHub Desktop.
Save oldergod/1d0408a5833e1d44640c to your computer and use it in GitHub Desktop.
Tour of Go Fibonacci
package main
import "fmt"
func fibonacci() func() int {
n1 := 1
n2 := 0
return func() int {
n1, n2 = n2, n1+n2
return n1
}
}
func main() {
f := fibonacci()
for i := 0; i < 10; i++ {
fmt.Println(f())
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment