Skip to content

Instantly share code, notes, and snippets.

@tyler
Created May 13, 2010 08:08
Show Gist options
  • Save tyler/399615 to your computer and use it in GitHub Desktop.
Save tyler/399615 to your computer and use it in GitHub Desktop.
def A(x,y)
if y == 0
0
elsif x == 0
2 * y
elsif y == 1
2
else
A(x - 1, A(x, y - 1))
end
end
puts A(1, 10) #=> 1024
puts A(2, 4) #=> 65536
puts A(3, 3) #=> 65536
def f(n)
# A(0, n)
2 * n
end
def g(n)
# A(1, n)
2 ** n
end
class Numeric
def tetration(x)
([self] * x).inject { |acc,exp| acc ** exp }
end
end
def h(n)
# A(2, n)
2.tetration(n)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment