Skip to content

Instantly share code, notes, and snippets.

@vosechu
Created June 4, 2013 23:26
Show Gist options
  • Save vosechu/5710491 to your computer and use it in GitHub Desktop.
Save vosechu/5710491 to your computer and use it in GitHub Desktop.
Factorial call tree
def factorial num
if num == 1
return 1
else
return num * factorial(num-1)
end
end
factorial(5)
5 * factorial(4)
5 * (4 * factorial(3))
....
5 * (4 * (3 * (2 * (factorial(1)))))
5 * (4 * (3 * (2 * (1))))
5 * (4 * (3 * (2))))
5 * (4 * (6))
5 * 24
120
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment