Created
January 24, 2018 18:07
-
-
Save kevsersrca/48583ce326fb0b28e6210cadcfe3db97 to your computer and use it in GitHub Desktop.
fibonacci
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 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