Skip to content

Instantly share code, notes, and snippets.

@danielrangelmoreira
Last active November 17, 2020 12:41
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save danielrangelmoreira/e38d3b58afc71582d9cf26e53bfefb84 to your computer and use it in GitHub Desktop.
Save danielrangelmoreira/e38d3b58afc71582d9cf26e53bfefb84 to your computer and use it in GitHub Desktop.
Fastest, coolest, fibonacci algorithm golang with dynamic programming
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))
}
@diegogaulke
Copy link

Thank you.
I will use it in my project with Gin framework, to show the performance of go with fib and gin framework.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment