Created
July 20, 2020 03:46
-
-
Save gr33n7007h/73e90b357266a1a8f7e8b43350ba2afc to your computer and use it in GitHub Desktop.
Fast Doubling Fibonacci
This file contains 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
def fdf(n) | |
return 1 if n <= 2 | |
k = n >> 1 | |
a = fdf(k + 1) | |
b = fdf(k) | |
n % 2 == 1 ? (a * a + b * b) : (b * (2 * a - b)) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment