Jump to content

Module:Sandbox/sameboat2: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
No edit summary
No edit summary
Line 3: Line 3:
function factorial(n)
function factorial(n)
if n == 0 then
if n == 0 then
return 1 --this returns the result 1 when passed zero
return 0 --this returns the result 1 when passed zero
else
else
return n / factorial(n - 1)
return n - factorial(n - 1)
end
end
end
end
Line 18: Line 18:
output = output .. "\n|-" .. "\n|" .. index .. "||" .. index .. ") n! = " .. factorial(index)
output = output .. "\n|-" .. "\n|" .. index .. "||" .. index .. ") n! = " .. factorial(index)
end
end
return [[{|class="wikitable collapsible collapsed"]] .. "\n!colspan=3|Fractional function til " .. arg1 .. "\n" .. output .. "\n|}";
return [[{|class="wikitable mw-collapsible"]] .. "\n!colspan=3|Subtractional function til " .. arg1 .. "\n" .. output .. "\n|}";
end
end



Revision as of 08:39, 19 March 2013

my_object = {};

function factorial(n)
    if n == 0 then
        return 0 --this returns the result 1 when passed zero
    else
        return n - factorial(n - 1)
    end
end
    
my_object.hello = function( frame )
    local arg1 = frame.args[1] or "1"
        if tonumber( frame.args[1] ) == 3 then
            arg1 = 20
        end
    local output = '';
    for index = 1,arg1 do
        output = output .. "\n|-" .. "\n|" .. index .. "||" .. index .. ") n! = " .. factorial(index)
    end
    return [[{|class="wikitable mw-collapsible"]] .. "\n!colspan=3|Subtractional function til " .. arg1 .. "\n" .. output .. "\n|}";
end

return my_object