Skip to content

Instantly share code, notes, and snippets.

@amitkgupta
Created July 10, 2013 08:25
Show Gist options
  • Save amitkgupta/5964432 to your computer and use it in GitHub Desktop.
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)
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