Fix "factorial" function in test case that was not actually factorial function.
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
15
|
120
|
||||||
15
|
120
|
||||||
1.2246467991473532E-16
|
1.2246467991473532E-16
|
||||||
1.2246467991473532E-16
|
1.2246467991473532E-16
|
||||||
|
|||||||
@@ -4,15 +4,15 @@ local function f(x)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function factorial(i)
|
local function factorial(i)
|
||||||
local function helper(sum, n)
|
local function helper(product, n)
|
||||||
if n <= 0 then
|
if n <= 0 then
|
||||||
return sum
|
return product
|
||||||
else
|
else
|
||||||
-- tail call to a nested Lua function
|
-- tail call to a nested Lua function
|
||||||
return helper(n + sum, n - 1)
|
return helper(n * product, n - 1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return helper(0, i)
|
return helper(1, i)
|
||||||
end
|
end
|
||||||
|
|
||||||
local result1 = factorial(5)
|
local result1 = factorial(5)
|
||||||
|
|||||||
Binary file not shown.
Reference in New Issue
Block a user