Last active
November 17, 2020 12:41
-
-
Save danielrangelmoreira/e38d3b58afc71582d9cf26e53bfefb84 to your computer and use it in GitHub Desktop.
Fastest, coolest, fibonacci algorithm golang with dynamic programming
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" | |
"math/big" | |
) | |
func fib(n int) *big.Int { | |
fn := make([]*big.Int, n+1) | |
for i := 0; i <= n; i++ { | |
var f = big.NewInt(0) | |
if i <= 2 { | |
f.SetUint64(1) | |
} else { | |
f = f.Add(fn[i-1], fn[i-2]) | |
} | |
fn[i] = f | |
} | |
return fn[n] | |
} | |
func main() { | |
fmt.Println(fib(300)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you.
I will use it in my project with Gin framework, to show the performance of go with fib and gin framework.