2021-10-29 21:25:12 +01:00
|
|
|
--[[
|
|
|
|
The Great Computer Language Shootout
|
|
|
|
http://shootout.alioth.debian.org/
|
|
|
|
contributed by Isaac Gouy
|
|
|
|
]]
|
2023-12-02 22:20:54 +00:00
|
|
|
local bench = script and require(script.Parent.bench_support) or pcall(require, "bench_support") or require("../../bench_support")
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
function test()
|
|
|
|
|
2022-05-06 01:03:43 +01:00
|
|
|
local function ack(m,n)
|
2021-10-29 21:25:12 +01:00
|
|
|
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) );
|
|
|
|
end
|
|
|
|
|
2022-05-06 01:03:43 +01:00
|
|
|
local function fib(n)
|
2021-10-29 21:25:12 +01:00
|
|
|
if (n < 2) then return 1; end
|
|
|
|
return fib(n-2) + fib(n-1);
|
|
|
|
end
|
|
|
|
|
2022-05-06 01:03:43 +01:00
|
|
|
local function tak(x,y,z)
|
2021-10-29 21:25:12 +01:00
|
|
|
if (y >= x) then return z; end
|
|
|
|
return tak(tak(x-1,y,z), tak(y-1,z,x), tak(z-1,x,y));
|
|
|
|
end
|
|
|
|
|
|
|
|
local result = 0;
|
|
|
|
|
|
|
|
for i = 3,5 do
|
|
|
|
result = result + ack(3,i);
|
2022-05-06 01:03:43 +01:00
|
|
|
result = result + fib(17+i);
|
2021-10-29 21:25:12 +01:00
|
|
|
result = result + tak(3*i+3,2*i+2,i+1);
|
|
|
|
end
|
|
|
|
|
|
|
|
local expected = 57775;
|
|
|
|
|
|
|
|
if (result ~= expected) then
|
|
|
|
assert(false, "ERROR: bad result: expected " .. expected .. " but got " .. result);
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
bench.runCode(test, "controlflow-recursive")
|