Skip to content

Instantly share code, notes, and snippets.

@brydavis
Last active April 17, 2019 18:59
Show Gist options
  • Save brydavis/81718ef9d2b8befe50dfd5b078ac3d3c to your computer and use it in GitHub Desktop.
Save brydavis/81718ef9d2b8befe50dfd5b078ac3d3c to your computer and use it in GitHub Desktop.
Fibonacci Examples
package main
import (
"fmt"
)
func main() {
fmt.Println(fib(9))
}
func fib(n int) int {
a, b, n := 0, 1, n - 1
for n > 0 {
a, b = b, a+b
n--
}
return b
}
package main
import (
"fmt"
)
func main() {
fmt.Println(fib(9))
}
func fib(n int) int {
if n <= 1 {
return n
}
return fib(n-1) + fib(n-2)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment