Last active
April 17, 2019 18:59
-
-
Save brydavis/81718ef9d2b8befe50dfd5b078ac3d3c to your computer and use it in GitHub Desktop.
Fibonacci Examples
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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