local p =
local function powerformat(divisor, power, productSymbol) if power < 1 then return elseif power
local function format(numString, bold, big, serif) if bold then numString = ''..numString..'' end
local ret = (serif or big) and '
' or ) .. numString .. ((serif or big) and '' or )return retend
function p.factor(frame) local number = tonumber(frame.args[1]) if number
math.huge then return 'Error: ' .. number .. ' out of range' end
local result = "" local currentNumber = number local power = 0 local divisor = 2 local productSymbol = frame.args['product'] or 'ยท' -- Attempt factoring by the value of the divisor -- divisor increments by 2, except first iteration (2 to 3) while divisor <= math.sqrt(currentNumber) do power = 0 while currentNumber % divisor
-- Concat result and increment divisor -- when divisor is 2, go to 3. All other times, add 2 result = result .. powerformat(divisor, power, productSymbol) divisor = divisor + (divisor
if currentNumber ~= 1 then result = result .. currentNumber .. ' ' .. productSymbol .. ' ' end
local primeLink = frame.args['prime'] and true if currentNumber
result = string.sub(result,1,-4)
local bold = frame.args['bold'] and true local big = frame.args['big'] and true local serif = frame.args['serif'] and true return format(result, bold, big, serif)end
return p