Module:Interval table: Difference between revisions
CompactStar (talk | contribs) No edit summary |
CompactStar (talk | contribs) No edit summary |
||
| Line 8: | Line 8: | ||
local function gcd(a, b) | local function gcd(a, b) | ||
return b==0 and a or gcd(b,a%b) | return b==0 and a or gcd(b,a%b) | ||
end | |||
local function table_contains(tbl, x) | |||
found = false | |||
for _, v in pairs(tbl) do | |||
if v == x then | |||
found = true | |||
end | |||
end | |||
return found | |||
end | end | ||
| Line 13: | Line 23: | ||
local function get_ratios_list(max_nd, max_size) | local function get_ratios_list(max_nd, max_size) | ||
local ratios = {} | local ratios = {} | ||
local ratio_strings = {} | |||
for i=1,max_nd do | for i=1,max_nd do | ||
for j=1,max_nd do | for j=1,max_nd do | ||
if (i/j) >= 1 and (i/j) <= max_size then | t = i/gcd(i,j) .. "/" .. j/gcd(i,j) | ||
if (i/j) >= 1 and (i/j) <= max_size and not tbl_contains(ratio_strings, t) then | |||
ratios[#ratios + 1] = {i/gcd(i,j),j/gcd(i,j)} | ratios[#ratios + 1] = {i/gcd(i,j),j/gcd(i,j)} | ||
ratio_strings[#ratio_strings + 1] = t | |||
end | end | ||
end | end | ||
end | end | ||