Created
July 10, 2013 08:25
-
-
Save amitkgupta/5964432 to your computer and use it in GitHub Desktop.
A very fast, near-constant runtime algorithm for determining whether a given number is Fibonacci, accurate up to numbers with trillions of trillions of digits (or something like that)
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 is_fibonacci?(num) | |
n = (Math.log(num*2.23606797749979 + 0.5) * 2.0780869213681945).floor | |
num == (1.6180339887**n * 0.4472135954999579).round | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment