Last active
December 20, 2015 10:31
-
-
Save MrBean83/6116094 to your computer and use it in GitHub Desktop.
#FibonacciSequence
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) | |
| n = i * Math.sqrt(5) | |
| n1 = Math.sqrt((5*(i**2)+4)) | |
| n2 = Math.sqrt((5*(i**2)-4)) | |
| if (i == 1 || i == 0) | |
| return true | |
| elsif (n1 % 1 == 0) || (n2 % 1 == 0) | |
| return true | |
| else | |
| return false | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment