Skip to content

Instantly share code, notes, and snippets.

@abrahamsangha
abrahamsangha / fibonacci
Created May 9, 2013 11:27
Check if a number i is part of the Fibonacci sequence. Attempted to use the integer square root method so that large numbers could be arguments, but no dice, yet.
def is_fibonacci?(i)
x = 5 * i**2 + 4
m = x
p = x
loop do
r = (m + p.to_f / m).to_f / 2
if m <= r
break
else