Changes

Jump to navigation Jump to search

Module:Math

80 bytes added, 12:15, 28 March 2016
simplify using a new binary_fold function, per protected edit request by User:Esquivalience
end
local function applyFuncToArgsfold(func, ...)
-- Use a function on all supplied arguments, and return the result. The function must accept two numbers as parameters,
-- and must return a number as an output. This number is then supplied as input to the next function call.
end
return ret, count
end
 
--[[
Fold arguments by selectively choosing values (func should return when to choose the current "dominant" value).
]]
local function binary_fold(func, ...)
local value = fold((function(a, b) if func(a, b) then return a else return b end end), ...)
return value
end
return result
end
 
--[[
function p._max(...)
local max_value = binary_fold((function maxOfTwo(a, b) if return a > b then return a else return b end end local max_value = applyFuncToArgs(maxOfTwo), ...)
if max_value then
return max_value
function p._min(...)
local min_value = binary_fold((function minOfTwo(a, b) if return a < b then return a else return b end end local min_value = applyFuncToArgs(minOfTwo), ...)
if min_value then
return min_value
function p._average(...)
local sum, count = fold((function getSum(a, b) return a + b end local sum, count = applyFuncToArgs(getSum), ...)
if not sum then
return 0
return oldr
end
local result, count = applyFuncToArgsfold(findGcd, ...)
return result
end
Anonymous user

Navigation menu