Problem 2982. Get a Fibonacci number's index.
N.B. For the purpose of this exercise, the first Fibonacci number is 1, and the second is 2; that is, fib(1) = 1 and fib(2) = 2 .
Make a function isfib(x) so that:
- if the value of the input x is not a Fibonacci number, the function returns a zero.
- if the value of the input x is a Fibonacci number, the function returns its index in the Fibonacci sequence. That is, isfib(fib(n)) should return the value of n .
Solution Stats
Problem Comments
-
2 Comments
5.731478440138172e+20 from 7th test is not a Fibonacci Number. 100th Fibonacci Number in proposed convention is 573147844013817084101 which has 21 digits and exceeds double precision.
I agree with Jan. http://www.maths.surrey.ac.uk/hosted-sites/R.Knott/Fibonacci/fibtable.html (this list begins at 0). The 100th fibonnaci number is 573147844013817084101 (5.731478440138171e+20), and not 5.731478440138172e+20.
Solution Comments
Show commentsProblem Recent Solvers50
Suggested Problems
-
Return the largest number that is adjacent to a zero
5506 Solvers
-
Number of 1s in the Binary Representation of a Number
475 Solvers
-
Make an awesome ramp for a tiny motorcycle stuntman
743 Solvers
-
502 Solvers
-
The Answer to Life, the Universe, and Everything
571 Solvers
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!