I am trying to solve a bigger problem, and I think that an important part of the program is spent on inefficient computations.
I need to compute for a given number N, th
On Scala find the closet Fibonaci number looks also very simple:
val phi = (1 + sqrt(5))/2 def fib(n: Long): Long = round( ( pow(phi,n) - pow((1-phi),n) ) / sqrt(5) ) def fibinv(f: Long): Long = if (f < 2) f else round( log(f * sqrt(5) ) /log(phi))