Fix "factorial" function in test case that was not actually factorial function.

This commit is contained in:
Ian Farmer
2007-09-05 03:02:57 +00:00
parent 75fb975410
commit 35131f9f66
3 changed files with 6 additions and 6 deletions

View File

@@ -1,4 +1,4 @@
15
15
120
120
1.2246467991473532E-16
1.2246467991473532E-16

View File

@@ -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.