Skip to content

Instantly share code, notes, and snippets.

View kexline4710's full-sized avatar

Kathryn Exline kexline4710

  • Exline Consulting
  • Columbus, OH
View GitHub Profile
@kexline4710
kexline4710 / gist:6445884
Last active December 22, 2015 08:38
This is my method to check if a given number is in the Fibonacci sequence by using the equation in the 'recognizing fibonacci numbers' section of this wikipedia page: http://en.wikipedia.org/wiki/Fibonacci_number#Recognizing_Fibonacci_numbers. I get that this can't handle large numbers as Float isn't precise enough at a certain point. Through my…
def is_fibonacci?(i)
fib1 = Math.sqrt((5*(i**2)+4))
fib2 = Math.sqrt((5*(i**2)-4))
puts fib1 == fib1.floor || fib2 == fib2.floor ? true : false
end