Skip to content

Instantly share code, notes, and snippets.

@kevsersrca
Created January 24, 2018 18:07
Show Gist options
  • Save kevsersrca/48583ce326fb0b28e6210cadcfe3db97 to your computer and use it in GitHub Desktop.
Save kevsersrca/48583ce326fb0b28e6210cadcfe3db97 to your computer and use it in GitHub Desktop.
fibonacci
package main
import (
"fmt"
"math/big"
)
func fibonacci(x int) *big.Int {
fibo := make(map[int]*big.Int)
for i := 0; i <= x; i++ {
var y = big.NewInt(0)
if i <= 2 {
y.SetUint64(1)
} else {
y = y.Add(fibo[i-1], fibo[i-2])
}
fibo[i] = y
}
return fibo[x]
}
func main() {
x := fibonacci(300000)
fmt.Printf("%v\n", len(x.String()))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment