Created
May 21, 2013 19:23
-
-
Save rwarbelow/5622468 to your computer and use it in GitHub Desktop.
Fibonacci Numbers
This file contains hidden or 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?(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