Skip to content

Instantly share code, notes, and snippets.

@tyler
Created May 24, 2010 20:06
Show Gist options
  • Save tyler/412362 to your computer and use it in GitHub Desktop.
Save tyler/412362 to your computer and use it in GitHub Desktop.
def recursive(n)
if n < 3
n
else
recursive(n - 1) +
2 * recursive(n - 2) +
3 * recursive(n - 3)
end
end
def iterative(n)
return n if n < 3
c = 0
b = 1
a = 2
3.upto(n).each do
x = a + 2*b + 3*c
c = b
b = a
a = x
end
a
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment