Skip to content

Instantly share code, notes, and snippets.

@ptflp
Last active January 23, 2020 23:20
Show Gist options
  • Save ptflp/f67cde81d3d6728d4bf710377458761d to your computer and use it in GitHub Desktop.
Save ptflp/f67cde81d3d6728d4bf710377458761d to your computer and use it in GitHub Desktop.
fibonacci sequence golang implementation
package main
import (
"fmt"
)
func fib() func() int{
a, b := 0, 1
return func() int{
a, b = b, a+b
return b-a
}
}
func main() {
t := fib()
for i:=0; i < 20; i++{
fmt.Println(t())
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment