Skip to content

Instantly share code, notes, and snippets.

@AlexYangYu
Created September 28, 2013 15:30
Show Gist options
  • Save AlexYangYu/6743157 to your computer and use it in GitHub Desktop.
Save AlexYangYu/6743157 to your computer and use it in GitHub Desktop.
Exercise: Fibonacci closure
package main
import "fmt"
func fibonacci() func() int {
x, y := 0, 1
return func () int {
x, y = x + y, x
return x
}
}
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