Skip to content

Instantly share code, notes, and snippets.

@dannycroft
Created September 22, 2017 17:09
Show Gist options
  • Save dannycroft/27de0dcbea56c85b2dbaeedd487f9ca9 to your computer and use it in GitHub Desktop.
Save dannycroft/27de0dcbea56c85b2dbaeedd487f9ca9 to your computer and use it in GitHub Desktop.
Fibonacci in GO
package main
import "fmt"
func fibonacci() func() int {
first, second := 0, 1
return func() int {
ret := first
first, second = second, first+second
return ret
}
}
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