Created
October 23, 2014 06:44
-
-
Save shionryuu/e85750d7b3896e3bfaf0 to your computer and use it in GitHub Desktop.
golang fibonacci generator
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" | |
) | |
/* | |
* fibonacci generator | |
*/ | |
func fibonacci() func() int64 { | |
var x, y, z int64 = 1, 1, 0 | |
return func() int64 { | |
z, x, y = x, y, x+y | |
return z | |
} | |
} | |
func main() { | |
Fibo := fibonacci() | |
for i := 0; i < 10; i++ { | |
fmt.Println(Fibo()) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment