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