What is happening and what are you expecting should happen instead? Please be more specific. Playground says “took too long”, but that might just mean that it exceeds the limit set by the playground and may be completely valid.
Generally speaking, the
math.Big API is a bit unusual. Take care to read carefully about what happens with the operands and where the result ends up.
If you change
for i := 0; i < 1000000; i++ to
for i := 0; i < 1000; i++ it works on the playground, so I think your code is fine and it’s just taking too long to complete like @calmh has suggested.
it just goes on processing and nothing is displayed. I was expecting a number , to be specific the index number of 1000th fibonacci number
Do you mean something like this? https://play.golang.org/p/7k_BcuqmQI.
P.S Don’t look if you want to just figure it out for yourself.
Edit: Made an error with my fib function, updated the link.
Edit 2: Once again replaced the link, realized the function was still wrong (haven’t hardly touched math/big before so still not sure if there’s a better way, but it works fine now ).
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.