Module:JI ratio finder: Difference between revisions
Added NEFTH filtering |
Changed candidate-ratio search to integer limit |
||
Line 63: | Line 63: | ||
-- Ratios found this way will range from 0 cents to the given cent value. | -- Ratios found this way will range from 0 cents to the given cent value. | ||
-- These ratios should then be filtered as needed. | -- These ratios should then be filtered as needed. | ||
function p.find_candidate_ratios(cents, | function p.find_candidate_ratios(cents, int_limit, prime_limit) | ||
local cents = cents or | local cents = cents or 1902 | ||
local | local int_limit = int_limit or 99 | ||
local prime_limit = prime_limit or 97 | local prime_limit = prime_limit or 97 | ||
local candidate_ratios = {} | local candidate_ratios = {} | ||
for i = 1, | for i = 1, int_limit do | ||
for j = i, int_limit do | |||
local numerator = j | |||
local denominator = i | |||
local | |||
local | |||
if | -- Proceed if ratio is simplified | ||
if utils._gcd(numerator, denominator) == 1 then | |||
local current_ratio = rat.new(numerator, denominator) | |||
local is_within_prime_limit = rat.max_prime(current_ratio) <= prime_limit | |||
local is_within_cents = rat.cents(current_ratio) <= cents | |||
if is_within_cents and is_within_prime_limit then | |||
table.insert(candidate_ratios, current_ratio) | |||
end | |||
end | end | ||
end | |||
end | end | ||
Line 96: | Line 95: | ||
-- within a prime subgroup. | -- within a prime subgroup. | ||
-- These ratios should be filtered as needed. | -- These ratios should be filtered as needed. | ||
function p.find_candidate_ratios_within_subgroup(cents, | function p.find_candidate_ratios_within_subgroup(cents, int_limit, subgroup) | ||
local cents = cents or 1200 | local cents = cents or 1200 | ||
local | local int_limit = int_limit or 99 | ||
local subgroup = subgroup or { 2, 3, 7, 11 } | local subgroup = subgroup or { 2, 3, 7, 11 } | ||
local candidate_ratios = {} | local candidate_ratios = {} | ||
for i = 1, | for i = 1, int_limit do | ||
for j = i, int_limit do | |||
local numerator = j | |||
local denominator = i | |||
local | |||
local | |||
if | -- Proceed if ratio is simplified | ||
if utils._gcd(numerator, denominator) == 1 then | |||
local current_ratio = rat.new(numerator, denominator) | |||
local is_within_subgroup = p.within_subgroup(current_ratio) | |||
local is_within_cents = rat.cents(current_ratio) <= cents | |||
if is_within_cents and is_within_subgroup then | |||
table.insert(candidate_ratios, current_ratio) | |||
end | |||
end | end | ||
end | |||
end | end | ||