Skip to content

Instantly share code, notes, and snippets.

@shionryuu
Created October 23, 2014 06:44
Show Gist options
  • Save shionryuu/e85750d7b3896e3bfaf0 to your computer and use it in GitHub Desktop.
Save shionryuu/e85750d7b3896e3bfaf0 to your computer and use it in GitHub Desktop.
golang fibonacci generator
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