Created
May 6, 2014 05:58
-
-
Save damianesteban/5adffd4480f41ab47aa9 to your computer and use it in GitHub Desktop.
basic fibonacci sequence print out
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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