Skip to content

Instantly share code, notes, and snippets.

@titanium-cranium
Created November 14, 2017 21:03
Show Gist options
  • Select an option

  • Save titanium-cranium/92a966f6ea8c31ba140a2b5eda0ae4f5 to your computer and use it in GitHub Desktop.

Select an option

Save titanium-cranium/92a966f6ea8c31ba140a2b5eda0ae4f5 to your computer and use it in GitHub Desktop.
Recursive version returning the value of an element in the fibonacci series
def fib(n)
return n if (0..1).include? n
fib(n-1) + fib(n-2) if n > 1
end
puts fib(7)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment