Last active
November 8, 2024 11:24
-
-
Save alenaksu/648e81f3c539b9360be119f0617662fb to your computer and use it in GitHub Desktop.
Fibonacci number generator using the Binet's formula
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
const fibonacci = (n: number): number => { | |
const delta = Math.sqrt(5); | |
return Math.floor(((1 + delta) ** n - (1 - delta) ** n) / (2 ** n * delta)); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment