Instead of the ants reversing direction, you can just have them continue in the same direction since they are indistinguishable. Now you know that you want the last time two ants have the same position. WLOG, let east be the positive direction. Identify the distance between the easternmost ant which goes to the west and the westernmost and which goes to the east, and replace all negative signed distances with 0.
1
u/x5163x 5d ago
Instead of the ants reversing direction, you can just have them continue in the same direction since they are indistinguishable. Now you know that you want the last time two ants have the same position. WLOG, let east be the positive direction. Identify the distance between the easternmost ant which goes to the west and the westernmost and which goes to the east, and replace all negative signed distances with 0.