Skip to content

Instantly share code, notes, and snippets.

@aturgarg
Last active September 19, 2020 09:54
Show Gist options
  • Save aturgarg/8ff3b8e6cd29cfdd6e7b341a91de9575 to your computer and use it in GitHub Desktop.
Save aturgarg/8ff3b8e6cd29cfdd6e7b341a91de9575 to your computer and use it in GitHub Desktop.
fibonacci without condition or recursion (in golang)
package main
import "fmt"
func fibonacci() func() int {
sum := 0
x := 0
y := 1
return func() int {
sum = sum + x
x = y
y = sum
return sum
}
}
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