Skip to content

Instantly share code, notes, and snippets.

@tuxskar
Created October 27, 2015 20:35
Show Gist options
  • Save tuxskar/b35aea178cc6ea226793 to your computer and use it in GitHub Desktop.
Save tuxskar/b35aea178cc6ea226793 to your computer and use it in GitHub Desktop.
One of my first programs in Go, the Fibonacci
package main
import "fmt"
func fibonacci() func() int {
a, b := 0, 1
return func() int {
b, a = a + b, b
return a
}
}
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