Skip to content

Instantly share code, notes, and snippets.

@strax
Created February 28, 2011 21:58
Show Gist options
  • Save strax/848129 to your computer and use it in GitHub Desktop.
Save strax/848129 to your computer and use it in GitHub Desktop.
var depth = 1, invocations = 0, substractions = 0, edge = 0;
function f(x, y, z) {
if(y < x) {
// Increment the counters
++depth
substractions += 3
if(depth > edge) edge = depth
console.log("Recursion depth: %d", depth)
z = f(f(x - 1, y, z), f(y - 1, z, x), f(z - 1, x, y))
// We are back
--depth
}
return z
}
var x = 18, y = 12, z = 6
f(x, y, z)
console.log("Maximum recursion depth: %d", edge)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment