Skip to content

Instantly share code, notes, and snippets.

@ajbeach2
Created June 13, 2015 03:41
Show Gist options
  • Save ajbeach2/3c0192e1e50b24268bca to your computer and use it in GitHub Desktop.
Save ajbeach2/3c0192e1e50b24268bca to your computer and use it in GitHub Desktop.
def fib(x, sequence = [])
if x <= 1
result = 1
elsif
result1 = sequence[x - 1] ||= fib(x - 1)
result2 = sequence[x - 2] ||= fib(x - 2)
result = result1 + result2
end
sequence[x] = result
return result
end
a = []
fib(a)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment