@user2179021 threw a program together to render the problem, http://visualmelon.onl/spindist.png (red lines are Y values, blue dots are X values)
can you clarify how the wrapping works - because your example solution seems to presume that you can't wrap the distance (i.e. 99 is closer to 80 then 1)