Talk:Mutsuki/@comment-16545476-20150422172808/@comment-24332640-20150423182326

Well yes, if you actually have a point at 99 then that makes things much simpler.

But for getting both with several data points I would essentially do a simple minimization routine. Except we're assuming that the min and max values should be integers so that actually makes things a lot simpler. In pseduo code it would be something like:

for i in range of possible min values

for j in range of possible max values (or if you have the level 99 value just use that)

slope = (j - i) / 98 (98 because we're assuming the min should be at level 1, right?  So it's 99-1)

intercept = min - slope (not exactly the same as min since this is the 'level 0' value)

initialize flag

for each data point

compute round_down(slope*(data point level) + min) - (data point value), if not equal to 0 set flag

endfor

if flag not set (all points are fit) this i, j are candidate min/max values. Note that if you don't have enough data points there can be more than one solution (the ambiguity from the rounding I mentioned), but really it out to be pinned down pretty quickly with a decent spread of points.

endfor

endfor

Note I'm a little unclear on whether the minimum we're talking about is the value at level 1 or the 'level 0' intercept but it's pretty easy to change the algorithm to try the other. Just change the 98 to 99 in the slope equation and the intercept would just be the min value for the other case. This does matter because I'm assuming integer values and perfect solutions. The question is whether it's the level 1 or 'level 0' value that's stored as an integer. It may not actually be possible to find a perfect solution if you use the wrong algorithm.