You are given an insect moves in a plane starting from the original point (0,0). The insect that can only move toward North-East, South-East, North-West, & South-West. Now the thing is insect can't move more than a specific number of steps at a time in one direction. For example, it can move only 3 steps in NE, 4 steps in SE, 5 steps in NW and 2 steps in SW.
If the insect moves 3 steps in direction NE at a stretch- it has to move NW, SE, or SW- before again going in direction NE.
How can I get the most efficient path to a given point in this situation? I am new to programming and came across this problem. Can anyone tell me a good approach to solve the kind of problems? Thank you.
My thoughts:
First, take a step in NE and SE to walk 2 steps in E. Similarly for N, S, and W. Now, find the shortest path. Basically, turn this problem into a simpler one instead of walking diagonally. (Not a good method. But can find a path.)
The second one is inspired by iterative methods used to find minima of 3-d curves. If I remove the limit on travelling in one direction at a time, we can do it by moving in the direction (one among the four) which takes us to the destination faster. This is similar to the gradient descent method but only four directions to move in.
Python code will be appreciated.