I know that we can brute force it by placing an obstacle at every valid position in the path, but is there a more elegant / efficient solution?

you are viewing a single comment's thread
view the rest of the comments
[–] 2 points 2 years ago

You can track by just keeping list of all positions and movement direction, if two are same, it means that it is in a loop.

  • source
  • parent