Created
September 25, 2018 00:31
-
-
Save jchung05/145eeb234e08ded86e4a0dbdd6589fdc to your computer and use it in GitHub Desktop.
An attempt at the A Tour of Go Fibonacci Closure exercise
This file contains 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 { | |
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