Skip to content

Instantly share code, notes, and snippets.

@rwarbelow
Created May 21, 2013 19:23
Show Gist options
  • Select an option

  • Save rwarbelow/5622468 to your computer and use it in GitHub Desktop.

Select an option

Save rwarbelow/5622468 to your computer and use it in GitHub Desktop.
Fibonacci Numbers
def is_fibonacci?(i)
tester1 = Math.sqrt((5*(i*i)) + 4)
tester2 = Math.sqrt((5*(i*i)) - 4)
if (tester1 - tester1.to_i) == 0 or (tester2 - tester2.to_i) == 0
return true
else
return false
end
end
#this code seems to work for all numbers except the last tester (927372692193078999171). I'm assuming
#this is because floating point numbers are not precise enough.
#Any suggestions?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment