Fibonacci numbers in Ruby
Example for versions
Ruby 1.8.5
This example uses recursive definition of Fibonacci numbers.
#! /usr/bin/env ruby
def fibonacci(n)
if n < 3
1
else
fibonacci(n - 1) + fibonacci(n - 2)
end
end
(1..16).each {|n| puts fibonacci(n)}
puts "..."
Comments
]]>blog comments powered by Disqus
]]>