Skip to content

Instantly share code, notes, and snippets.

@rranelli
Created October 22, 2018 23:30
Show Gist options
  • Save rranelli/721d23b716b90bcf7c173340325d1b52 to your computer and use it in GitHub Desktop.
Save rranelli/721d23b716b90bcf7c173340325d1b52 to your computer and use it in GitHub Desktop.
# fibo O(n^2)
def fib(n)
raise ArgumentError if n < 0
if n == 0 || n == 1
1
else
fib(n-1) + fib(n -2)
end
end
(1..30).each do |n|
puts "#{n} => #{fib(n)}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment