Created
October 13, 2020 05:28
-
-
Save aershov24/7356b5ce2e5bae3a91bc26edbe28afa5 to your computer and use it in GitHub Desktop.
Markdium-14 Fibonacci Interview Questions (SOLVED) To Brush Before Coding Interview
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
| static double inverseSqrt5 = 1 / Math.Sqrt(5); | |
| static double phi = (1 + Math.Sqrt(5)) / 2; | |
| /* should use | |
| const double inverseSqrt5 = 0.44721359549995793928183473374626 | |
| const double phi = 1.6180339887498948482045868343656 | |
| */ | |
| static int Fibonacci(int n) { | |
| return (int)Math.Floor(Math.Pow(phi, n) * inverseSqrt5 + 0.5); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment