Skip to content

Instantly share code, notes, and snippets.

@jchung05
Created September 25, 2018 00:31
Show Gist options
  • Save jchung05/145eeb234e08ded86e4a0dbdd6589fdc to your computer and use it in GitHub Desktop.
Save jchung05/145eeb234e08ded86e4a0dbdd6589fdc to your computer and use it in GitHub Desktop.
An attempt at the A Tour of Go Fibonacci Closure exercise
package main
import "fmt
func fibonacci() func() int {
x := 0
y := 1
z := 0
return func() int {
z, x, y = x, y, x + y
return z
}
}
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