PROBLEM
For a list of numbers, list
: Find the lowest possible integer, x
, which is optimally close to the whole number even-harmonics of the values in list.
list
has a length of n, and all of the values in list are <= 2000x
has a precision of 1.0 (integers only), and must be a value in the range [20, 100]- An even-harmonic is a number that is divisible by
list
an even number of times. 20 is an even harmonic of 80 (because 80/20=4) -- but an odd harmonic of 60 (because 60/20=3). - In this case, "optimally close" simply means to minimize the absolute cumulative remainder, relative to the nearest even harmonic of the input value(s).
- Minimizing the absolute cumulative error takes priority over choosing the "lowest allowable value" for
x
. - Given
list = [151, 450, 315]
and a candidate guess ofx=25
the absolute cumulative remainder is 0.64 because 25 goes intolist
[6.04, 18, 12.6] times, respectively. The nearest even-harmonics for each instance are [6, 18, 12].
- Minimizing the absolute cumulative error takes priority over choosing the "lowest allowable value" for
EXAMPLE
list = [100, 300, 700, 1340]
x = 20
is a bad solution because it is an exact or almost-exact odd-harmonic of all of the values oflist
. The number 20 goes intolist
[5, 15, 35, 67] times, respectively (odd numbers = odd harmonics = the opposite of even-harmonics).- The absolute cumulative remainder is 4.0 in this case (which is the maximum possible error for this instance of
list
).
- The absolute cumulative remainder is 4.0 in this case (which is the maximum possible error for this instance of
x = 25
is a good solution, but not the best, because it is a exact or almost-exact even-harmonic of all of the values of list. In this case, 25 is an exact even-harmonic in all cases except for 1340. The number 25 goes intolist
[4, 12, 20, 53.6] times, respectively (even numbers).- The absolute cumulative remainder is 0.4 in this case.
BONUS
Same prompt and problem, except x has a maximum precision of 0.1 (non-integer)
[100, 300, 700, 1340]
one, for which it is not.213
\$\endgroup\$