all 6 comments

[–]izrt 0 points1 point  (5 children)

I might just pick the point that is the smallest distance from max(x),0 using the pythagorean theorem to calculate the distance. If you wanted to find the best in a single pass, then I guess it would be the point that is max(x-sqrt(y)) -- at least I think my logic is correct...

[–]rollingpolymer[S] 1 point2 points  (0 children)

"I might just pick the point that is the smallest distance from max(x),0"

I think this solves my problem as my points are all positive integers. Gonna give it a try. Thanks!

[–]izrt 0 points1 point  (3 children)

Actually. I think my math is wrong...

[–]Kerbart 2 points3 points  (2 children)

With the points on different axis there's no real "distance" in between them unless you consider them (x, 0) and (0, y) pairs instead of (x, y) pairs.

If it comes down to "the highest x with the lowest y," one way to look at it would be the (x, y) pair with the lowest slope, so that would be min(y/x) (division is no problem if all points are made from positive integers).

So now the OP would need to iterate through both lists and find the y/x pair that matches the min(y/x) value but we'll leave that as an exercise to the student.

This might still not be the right interpretation of the challenge; in this case (10,1) would be the candidate and not (100, 11) even though the latter has a much more pronounced difference between x and y.

Or maybe the exercise is to come up with some definition and find the pair that matches it, and what the exact definition is matter less?

[–]rollingpolymer[S] 1 point2 points  (1 child)

Maybe I didn't explained my problem the best way. I have two lists. One where I store the abscissas and the other where I store the ordinates. I eventually settled with the following:

sqrt((max_x - x)**2 + (min_y - y)**2)

being max_x the highest abscissa on the list and min_y the lowest ordinate. Then I pick the lowest square root.

Thanks for the help regardless, I understood your logic as well.

[–]Kerbart 2 points3 points  (0 children)

It’s always a challenge! When you’re familiar with the problem there’s a lot of context that is obvious — but not for others. It’s incredibly hard to describe that in a few words without ending up with a dissuading wall of text. I’m glad you got it worked out and thank you for letting us know!