I could not find anything about this online. I’ll explain what it means here, it basically means that I want to find two numbers that multiply together to make an answer. Multiplicand is the first number, Multiplier is the second and Product is the answer.
Uniform means closest, for example 1 * 100 = 100 but if I wanted it to be Uniform I would do 10 * 10 = 100. Square rooting will only give integers for square numbers. In the example below I use 234 which is not a square number.
local function Sort(A, B)
return math.abs(A.Multiplier - A.Multiplicand) < math.abs(B.Multiplier - B.Multiplicand)
end
local function GetUniformMultiplicandAndMultiplier(Product)
local Array = {}
for Count = 1, Product do
if Product % Count == 0 then
table.insert(Array, {
Multiplicand = Count,
Multiplier = Product / Count
})
end
end
table.sort(Array, Sort)
return Array[1], Array[1]
end
local Product = 234
local Dictionary = GetUniformMultiplicandAndMultiplier(Product)
print(("%d * %d = %d"):format(Dictionary.Multiplicand, Dictionary.Multiplier, Product)) --> 13 * 18 = 234
Efficiency, is this the best way to approach something like this, since I could not find anything online this is the method I have used. Maybe there is a better one.