Skip to content

Instantly share code, notes, and snippets.

@Stephenitis
Last active December 14, 2015 02:09
Show Gist options
  • Save Stephenitis/5011550 to your computer and use it in GitHub Desktop.
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.
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