Last active
December 14, 2015 02:09
-
-
Save Stephenitis/5011550 to your computer and use it in GitHub Desktop.
Exercise: Fibonacci number
Check, if a number i is part of the Fibonacci sequence.
This file contains 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) | |
fib1 = 0 | |
fib2 = 1 | |
while fib1 <= i | |
fib1, fib2 = fib2, fib1 + fib2 | |
end | |
if fib1 == i | |
return true | |
else | |
return false | |
end | |
end | |
def is_fibonacci?(i) | |
a,b=0,1 | |
until b >= i | |
a,b=b,a+b | |
return true if b == i | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment