Skip to content

Instantly share code, notes, and snippets.

@georgespingos
Last active December 9, 2015 19:28
Show Gist options
  • Save georgespingos/4317570 to your computer and use it in GitHub Desktop.
Save georgespingos/4317570 to your computer and use it in GitHub Desktop.
Calculate Fibonacci without recursion or loops !! (Math hack)
public static double SuperCoolFibonacci(int n)
{
return Math.Round((Math.Pow(0.5 + 0.5 * Math.Sqrt(5.0), n) - Math.Pow(0.5 - 0.5 * Math.Sqrt(5.0), n)) / Math.Sqrt(5.0), MidpointRounding.AwayFromZero);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment