Skip to content

Instantly share code, notes, and snippets.

@damianesteban
Created May 6, 2014 05:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save damianesteban/5adffd4480f41ab47aa9 to your computer and use it in GitHub Desktop.
Save damianesteban/5adffd4480f41ab47aa9 to your computer and use it in GitHub Desktop.
basic fibonacci sequence print out
# Outputs a Fibonacci sequence, the length of the sequence being determined by the user.
puts "How many numbers from the sequence would you like to see?"
a = gets.chomp.to_i
def fib(n)
return n if (0..1).include? n
fib(n-1) + fib(n-2) if n > 1
end
a.times do |i|
puts fib(i)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment