Module:JI ratios: Difference between revisions

Ganaram inukshuk (talk | contribs)
code for finding products (not yet ratios) within a subgroup, to be expanded to find ratios; comments, rationale; testing
Ganaram inukshuk (talk | contribs)
save running changes to subgroup search
Line 151: Line 151:
local curr_max_multiplier = math.floor(max_product/curr_factor)
local curr_max_multiplier = math.floor(max_product/curr_factor)
local max_power = math.log(max_product) / math.log(curr_factor)
local max_power = math.log(max_product) / math.log(curr_factor)
table.insert(max_powers, math.floor(max_power))
table.insert(max_powers, math.ceil(max_power))
table.insert(curr_powers, 0)
table.insert(curr_powers, -max_powers[i])
end
end
-- Increment current powers one by one
-- Increment current powers one by one, and add to a table containing
-- vectors of powers; this table also contains vectors with negative powers
local powers = {}
while curr_powers[#curr_powers] < max_powers[#max_powers] do
while curr_powers[#curr_powers] < max_powers[#max_powers] do
curr_powers[1] = curr_powers[1] + 1
curr_powers[1] = curr_powers[1] + 1
for i = 1, #factors - 1 do
for i = 1, #curr_powers - 1 do
if curr_powers[i] > max_powers[i] then
if curr_powers[i] >= max_powers[i] then
curr_powers[i] = 0
curr_powers[i] = -max_powers[i] + 1
curr_powers[i+1] = curr_powers[i+1] + 1
curr_powers[i+1] = curr_powers[i+1] + 1
end
end
end
end
local curr_product = 1
local new_powers = {}
for i = 1, #curr_powers do
for i = 1, #curr_powers do
curr_product = curr_product * math.pow(factors[i], curr_powers[i])
table.insert(new_powers, curr_powers[i])
end
if curr_product <= max_product then
table.insert(products, curr_product)
end
end
table.insert(powers, new_powers)
end
end
table.sort(products)
table.sort(products)
return max_powers
return powers
end
end