Lurker News

Comments (491) 209 threads

Earlier comments
maksa1 reply#
Problem: are two points in the same polygon? Solution: a line drawn between those two points has an odd number of intersections with the polygon if they are both in it (or outside of it), and even number if they are not.
kazinator#
That's under-informative, we only know that both points are in the same polygon or outside of it. The underlying elegant algorithm is that of knowing whether a point is inside a polygon: a ray from that point out to infinity intersects the polygon an odd number of times if the point is in it, even otherwise.
busterarm#
Rock, Scissors, Paper in a circular array.

All you have to do to test for win condition is check if the other player has the next item in the array.
Equality is a tie.
Base case is a loss.
It's also my favorite case of structuring data in a way that makes the algorithm self-evident.

Load more comments