Skip to content
This repository has been archived by the owner on Jul 31, 2021. It is now read-only.

Commit

Permalink
Tweak ackermann
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcrichton committed May 8, 2012
1 parent 77469f9 commit a0dfba9
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions bench/ackermann.lua-2.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,17 @@
-- Submitted by Matthew Burke <shooutout@bluedino.net>
--
local function Ack(m, n)
if m == 0 then return n+1 end
if n == 0 then return Ack(m-1, 1) end
return Ack(m-1, Ack(m, n-1))
local ret
if m == 0 then
ret = n+1
elseif n == 0 then
ret = Ack(m-1, 1)
else
local t = Ack(m, n - 1)
ret = Ack(m-1, t)
end
return ret
end

local N = tonumber(arg and arg[1]) or 7
local N = tonumber(arg and arg[1]) or 9
io.write("Ack(3,", N ,"): ", Ack(3,N), "\n")

0 comments on commit a0dfba9

Please sign in to comment.