Skip to content

Instantly share code, notes, and snippets.

@ripiuk
Created January 30, 2019 09:11
Show Gist options
  • Save ripiuk/6b05457f42f09837fdf33ac565ffedbd to your computer and use it in GitHub Desktop.
Save ripiuk/6b05457f42f09837fdf33ac565ffedbd to your computer and use it in GitHub Desktop.
go tour exercise (moretypes/26)
package main
import "fmt"
func fibonacci() func() int {
x1 := 0
x2 := 1
res := 0
return func() int {
res, x1, x2 = x1, x2, x1 + x2
return res
}
}
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