Last active
August 29, 2015 14:06
-
-
Save oldergod/1d0408a5833e1d44640c to your computer and use it in GitHub Desktop.
Tour of Go Fibonacci
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 { | |
n1 := 1 | |
n2 := 0 | |
return func() int { | |
n1, n2 = n2, n1+n2 | |
return n1 | |
} | |
} | |
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