There are no reviewed versions of this page, so it may not have been checked for adherence to standards.

Documentation for this module may be created at Module:Factorial/doc

local p = {}

function p.factorial(frame)
    return p._factorial(tonumber(frame.args[1] or frame.args.x or frame.args.n or frame.args.m or 0))
end
function p.factorial_to(frame)
    return p._factorial_to(tonumber(frame.args[1] or frame.args.x or frame.args.n or frame.args.m or 0))
end
function p._factorial(n)
    if n == 0 then
        return 1
    else
        return n * p._factorial(n - 1)
    end
end

function p._factorial_to(n)
    local s = "";
    for index = 0,n do
        s = s .. index .. "! = " .. p._factorial(index) .. "<br />"
    end
    return s
end

return p