Skip to content

Instantly share code, notes, and snippets.

@jkaihsu
Created March 7, 2013 08:22
Show Gist options
  • Save jkaihsu/5106428 to your computer and use it in GitHub Desktop.
Save jkaihsu/5106428 to your computer and use it in GitHub Desktop.
Check, if a number i is part of the Fibonacci sequence.
def is_fibonacci?(i)
sum = [0,1]
x = 0
y = 0
while sum.max <= i
sum.length.times do |a|
x = sum[a] + sum[a-1]
end
sum = sum.push(x)
y +=1
end
#puts "#{sum} #{y}"
sum.include?(i)
puts "#{sum.max} #{sum.include?(i)}"
end
@mysticaltech
Copy link

mysticaltech commented Feb 8, 2018

Thanks for this! The variable y is just for observation yes, no real purpose in the algo?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment