Skip to content

Instantly share code, notes, and snippets.

@dtothefp
Created January 7, 2014 16:18
Show Gist options
  • Select an option

  • Save dtothefp/8301783 to your computer and use it in GitHub Desktop.

Select an option

Save dtothefp/8301783 to your computer and use it in GitHub Desktop.
class FibSequence
def initialize
@first = 0
@second = 1
end
def find_fib(n)
i = 2
print @first.to_s + " "
print @second.to_s + " "
while i <= n.to_i
sum = @first + @second
@first = @second
@second = sum
i += 1
print sum.to_s + " "
end
sum
end
end
fib = FibSequence.new
puts "\nYour Fib number is #{fib.find_fib(5)}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment