You're at integer coordinates \$(x,y)\$ facing one of North, South, East, or West. Your goal is to walk home to \$(0,0)\$. At each step, you may do one of:
- Walk one step in the current facing direction, that is to whichever of \$(x+1,y)\$, \$(x-1,y)\$, \$(x,y-1)\$, or \$(x,y+1)\$ you're facing.
- Rotate 90 degrees left, staying in place.
- Rotate 90 degrees right, staying in place.
Your goal is to write code that will eventually get you home to \$(0,0)\$ if called repeatedly, each time with your current position and facing. Your code must always give the same output for a given input, which precludes using randomness or past state.
Input:
Two integers \$(x,y)\$ and a facing direction. The 4 possible facing directions are given as numbers 0 through 3, or alternatively 1 through 4, matched as you choose. The position can also be taken as a vector or point or complex number.
You won't be given \$(0,0)\$ where you're already home. Don't worry about overflows caused by huge inputs.
Output:
One of three distinct consistent outputs corresponding to the possible actions of walking straight, turning left, and turning right.