Created
January 30, 2019 09:11
-
-
Save ripiuk/6b05457f42f09837fdf33ac565ffedbd to your computer and use it in GitHub Desktop.
go tour exercise (moretypes/26)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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