[Question]
  [
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.
  
[Answer]
# [Haskell](https://www.haskell.org/), 21 bytes
```
(!!).([(<0),(>0)]<*>)
```
[Try it online!](https://tio.run/##y0gszk7Nyflfraus4JOYl16amJ6q4BwQoKxby5VmG/NfQ1FRU08jWsPGQFNHw85AM9ZGy07zf25iZp6CrUJKPpeCQkFRZl6JgopCmkK0kY6uUayCIYagIRZBBQMcgkaogobYBA0ggv8B "Haskell – Try It Online")
Outputs a boolean with `True` being move forward and `False` being turn right.
# [Haskell](https://www.haskell.org/), 28 bytes
Here's a version that is easy to understand / translate into any language.
```
f(x,y)d=[x<0,y<0,x>0,y>0]!!d
```
[Try it online!](https://tio.run/##y0gszk7Nyfn/P02jQqdSM8U2usLGQKcSiCvsgLSdQayiYsr/3MTMPAVbhZR8LgWFgqLMvBIFFYU0BQ0jHV0jTQVDDEFDLIIKBjgEjVAFDbEJGkAE/wMA "Haskell – Try It Online")
## Explanation
The idea here is two-fold
* We notice that we only ever need to turn in one direction. A turn left is just 3 turns right. So we will limit ourselves to only right turns.
* Now we notice that given a direction there is a simple condition that can check if we ought to move forward. Namely the sign of one of the two variables.
With this information we construct out solution, by making a list of the conditions and indexing the list with the direction. `True` means the condition was passed and we can move forward (so we do), `False` means the condition was failed and we should not move forward, so we rotate.
Now the specification allows us to just output these values as is, since they are distinct and we have no intention of turning left.
[Answer]
# [Pyth](https://github.com/isaacg1/pyth), 7 bytes
```
qi<L0E2
```
[Try it online!](https://tio.run/##K6gsyfj/vzDTxsfA1ej//2gDHQWDWC5DAA "Pyth – Try It Online")
Input is in the form:
```
3
[3, 4]
```
The solution is simple:
* `<L0E` maps each coordinate to `0` if the coordinate is positive, and `1` if the coordinate is nonpositive.
* `i ... 2` converts the list to a number by interpreting it as binary.
* `q` checks whether the resulting number is equal to the other input.
* `True` means forward, `False` means turn, the direction is irrelevant, the third output is irrelevant.
We use the following mapping:
* `0`: up - the positive y direction.
* `1`: right - the positive x direction.
* `2`: left - the negative x direction.
* `3`: down - the negative y direction.
The path the walk takes is a sort of a staircase - from the `(-, -)` quadrant to `(-, 1)` to `(1, 1)` to `(0, 1)` to `(0, 0)` for instance.
[Answer]
# [Python 2](https://docs.python.org/2/), 30 bytes
```
lambda i,d:abs(i+1j**d)<abs(i)
```
[Try it online!](https://tio.run/##VYw9DoMgGIZnOQUdmoB8TaR1MuUEHsE6aICIoDXVpHJ6CjYdurzJ8/4tfhue8zVo8Qium3rZYQOy6vqVGMbHPJf0fgANUmlckx08WFqh7D0YpzDZmc/5SE@iGKOZLS8zb/goRTIaa/KrpFlKxM4aDgVcorSNbcGzpoCvkzjulFtVha0glnF6LtHfLarJDUrgNHwA "Python 2 – Try It Online")
Takes as input a Gaussian integer for position, and an integer in `{0,1,2,3}` for the direction; outputs `True` for forward, `False` for rotate counter-clockwise, and whatever you like for rotate clockwise, because that never happens :).
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 4 bytes
```
>-Ḅ⁼
```
[Try it online!](https://tio.run/##AXIAjf9qZWxsef//Pi3huITigbz/MTF4MljigqxfNSAsNFjigJnCpCxA4oCY4buLw5guLFU7VU4kJMKkK8qLwqVAL@KAmCU0xooywqbDpy8/4bq44oKs4biiJMOQwr/CteG5vjvigJwgLT4g4oCdO8OnLylZ//8 "Jelly – Try It Online")
A dyadic link taking the co-ordinates as the left argument and the direction faced as the right. Returns `0` for turn and `1` for move forwards.
The TIO footer picks a random starting point and demonstrates that the link will ultimately reach `[0,0]`
Based on [@isaacg’s Pyth answer](https://codegolf.stackexchange.com/a/198752/42248) so be sure to upvote that one too!
## Explanation
```
>-   | Greater than -1
  Ḅ  | Convert from binary time decimal integer
   ⁼ | Equal to right argument
```
[Answer]
# [J](http://jsoftware.com/), ~~12~~ 11 bytes
```
[>&|[+0j1^]
```
[Try it online!](https://tio.run/##PY5BS8NAEIXv8yueObgNXZct9bQQD614Eg9ei4U0meCmdRe2jabgf48TEz0MzMz7eO@1Q2ZUg8JBQcPCydwZbF@fn4bdw@33bmnb1f5tyIleNgafnA5oYsIlInUBsUv4KH1AzZU/@xgm4lBWxxGx2pJggZME3MNZIq7eIxaZ63OtNJTO3JXINwZ9YVFHQ8Avoh5j4BslZ@JLl4IhDrUh@ipPx0JoNLhS7ZPs0hB7zDajPvsseiwhSI6pgyB8OvMo9f8vQVaTdT6XW7frP9UOPw "J – Try It Online")
## idea
Our idea is simple: Walk straight, and see if that gets us closer in Euclidean distance. If yes, return "walk straight". If not, return "turn left".
## input / output
Take position as a complex number (left arg) and direction as a 0-indexed int (right arg). Similar to @PostRockGarfHunter's answer, we constrain our output to two values:
1. `1` - Walk straight
2. `0` - Turn left
## how
1. `[+0j1^]` First we convert our right arg integer to a complex number by raising *i* `0j1` to the right arg `0j1^]`. Then we add that `+` to the left arg `[`. This represents our "next position", if we were to walk straight.
2. `[>&|` Is the left arg `[` (current position) greater than `>` the next position after converting both to Euclidean distance from origin `&|`?
[Answer]
# [APL (Dyalog Classic)](https://www.dyalog.com/), ~~10~~ 9 bytes
```
⊣⊃0(>,<)⊢
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT9dNzkksLs5M/v@ob2pm/qO2CQb/H3UtftTVbKBhp2Oj@ahr0f80oOij3j6g2KH1xo/aJgJVFhclA8mSjMzi/@lA2epHvVsfdS40UDCwMnjU3VIE1rArDSTa3WKorWFSA@Tq1hVpPupoBwpqFx2eDhQAGqhhqGCgqWGgYKipcWg9lA1kaNZyaTzq3WwCVD9DL10hTxfIMXrUu8VQ2@jw9Dyg6cYA "APL (Dyalog Classic) – Try It Online")
all credit to [Post Rock Garf Hunter's answer](https://codegolf.stackexchange.com/a/198738/24908)
the tio link shows numbers of steps for the square area around (0,0) for the 4 initial directions
`⊣` left arg: direction
`⊢` right arg: coord pair
`,` concatenation
`0(>,<)⊢` is equivalent to `(0>⊢),(0<⊢)`, i.e. the 4-vector `(0>x),(0>y),(0<x),(0<y)`
`⊣⊃`.. indexing with the left arg
[Answer]
# [JavaScript (Node.js)](https://nodejs.org), 26 25 24 bytes
```
(x,y,d)=>--d%2*x<--d%2*y
```
[Try it online!](https://tio.run/##XY9BboMwEEXX4RRfSJWgmCakXZWQbQ@BskDYBCoXRxi1WA1npx5MSVovZsb@b/6M34vPQpddc@njVnExVdkUDMwwHmbHOOYP@8fh4LKZKtUhkKKHHpAhTnYpVQckCRVRFOLbgz03zqyc@eXMjfvLcssSyS35QtmBG6IIoJl6YCBPbRiI1zx1wKXoa3sfEMFnvo0GkSs4Pb36C/dVN1IgGHC9wqz2m6ZCUAVkbn3D@X0WrF@GPE4YdgwUTzk/pYtoZnERmP3nvTgvZHX/SKM3I4TUYvWl3XPbtmd4/ue6Nnau0W24pO22VK1WUjxJdQ4IDS00eg4ZvXvVf1M9avUh0LQopEQvdI@y0EL7YTr9AA "JavaScript (Node.js) – Try It Online")
`d` is direction one of `[0, 1, 2, 3]` for [west, north, east, south]
The expression  
`(d - 1) % 2` gives `deltaX` one of `[-1, 0, 1, 0]`and  
`(d - 2) % 2` gives `deltaY` one of `[0, -1, 0, 1]`
Either `x * deltaX` or `y * deltaY` will be non zero and will be negative if we are heading towards home. So if  
`(deltaX * x + deltaY * y < 0)` also expressed as  
`(deltaX * x < deltaY * -y)`
we go forward = `true`, else we turn left = `false`.
To get to 24 I swapped north and south to change '-y' to 'y'
[Answer]
# JavaScript (ES6), ~~28~~ 27 bytes
Takes input as `(x,y,d)` with \$d=0\$ for *North*, \$1\$ for *South*, \$2\$ for *West*, \$3\$ for *East*.
Output:
* *true* : turn right
* *false* : walk straight
```
(x,y,d)=>(x&&2|x<0||y<0)!=d
```
[Try it online!](https://tio.run/##XZBBbsMgFET3PsV0E4GKI@yomxKSg1heoIDbRFaIbDcClZzdBTu1FC9AGubN/yMu6q76U3e@DfnVajM2ciSOeaapPBC32ZTB7XkIfs/pm9TjYPoBEhGBZ9AU8oDfDGhsR1Q0qlrAIQR4QScDUNvbT/9NqmeEoYtcs0yoqcgm7tyQ7j8D6DRsx1AycIairnQtJusx3abtzcI6vMsUkChxRF7gc1a7qJLg4gn6BeQvYPEKphXprJqnpsDJXnvbmm1rv4iKL48sS59C8MGAWJjTWecrnfx85c96/AM "JavaScript (Node.js) – Try It Online")
### How?
This is parsed as:
```
           +--------------------> 0 if x = 0, 3 if x < 0, 2 if x > 0
           |                +---> 1 if the first expression is 0 and y < 0, 0 otherwise
   ________|_______        _|_
  /                \      /   \
((x && (2 | (x < 0))) || (y < 0)) != d
```
[Answer]
# [Retina 0.8.2](https://github.com/m-ender/retina/wiki/The-Language/a950ad7d925ec9316e3e2fb2cf5d49fd15d23e3d), ~~38~~ 35 bytes
```
. (-?).*( -?).*
$*-$2$1$1
^(-*) \1$
```
[Try it online!](https://tio.run/##TccxCoAwDEDRPafIEKEtpDSpzo5eQkQHBxcH8f4VEhSX//jXfh/n1rowrS1j4DHmFNAASkxKQgJL4BRxFmpNcMAK1arW8lWtYi1WFpCX3qmOOuIUh23r3wJqPA "Retina 0.8.2 – Try It Online") Link includes demonstration of path taken from `5 3` to the origin. Takes input as direction first, then coordinates. Edit: Saved 3 bytes by porting @isaacg’s Pyth answer. Direction encodes as `y--`, `x--`, `x++`, `y++`. Outputs `1` to move, `0` to turn. Explanation:
```
. (-?).*( -?).*
```
Capture the signs of the coordinates.
```
$*-$2$1$1
```
Convert the direction to unary, and convert the coordinate signs from base 2, discarding everything else.
```
^(-*) \1$
```
Compare the direction to the base 2 decoded signs.
[Answer]
# [C (gcc)](https://gcc.gnu.org/), 47 bytes
```
z;m(x,d)int*x;{x=abs(z=x[d/2])>abs(z+d%2*2-1);}
```
Returns `0` to move forward and `1` to turn clockwise. It never moves counterclockwise but let's just call that `2`.
North is `3`, south is `2`, east is `1`, and west is `0`.
*-2 bytes thanks to [ceilingcat](https://codegolf.stackexchange.com/users/52904/ceilingcat)!*
[Try it online!](https://tio.run/##dVJNT4NAEL3zKyaYJkDBFjx4QJp4aOLJJrbGA3Kou9Ru5MMAtVjKb8edZYFKdC/73uzMezOTJdY7IU1zcmOtNKnOksIo3ar0tm@5dvJKn86cQF8INqUTx3AsW3fr5oolJDrQEO7ygrL0er9QlDA5xEBZFpKCpYlSKcDP4@pp8wAe3JiCrlfPgjotXd6vN5zZLXtZCjY3ldodywGJUvJxZHnoB@BJcR/rOW1lWxFfYAyinIwhxJDoRsYExiCKtJZkv83A4J55kV3a9KmqQOrYSRWoC3dNqQjUUQcqArW148uGeMsS7StlVJdmGCRpmtHcd7Cgsuy5Cbc8H19HS@Gom57rYcJxz6JQkwLzAM7nTs0OdJHR2uD5zLjZTlNLrjGhJnzLm@Kdvyay94vT65qDqglyYfwKdLcvYTstlo2IFF3vn6pfujgx45Y4zKz7GZfnJB8n4IABjqv80RLDXQ14yosssIfUukdhlIf/dNKuc/hpONFYolbq5gc "C (gcc) – Try It Online")
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), 4 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
```
d2βQ
```
Port of [*@NickKennedy*'s Jelly answer](https://codegolf.stackexchange.com/a/198766/52210), so make sure to upvote him as well!
First input is the coordinate, second input is the current direction digit (in the range `[0,3]`).  
Outputs `0` to turn, and `1` to move forward.
[Try it online](https://tio.run/##yy9OTMpM/f8/xejcpsD//6N1jXWMYrkMAQ) or [verify a random coordinate will eventually result in `[0,0]`](https://tio.run/##yy9OTMpM/R/ionF0h8u5lcXnVj5qmBVqfHjuuZVh0REu9vEBykoKiXkpCkr2kfZKCo/aJoFYEf9TjM5tCvxvmxkRGZ9pYBisfXh1ZGYImLIB0rqHVwMFdWtra0OBInYmqmG1/wE) or [verify all coordinates in the range `[[-1,1],[1,1]]` with all possible directions `[0,3]`](https://tio.run/##yy9OTMpM/W98eK6hi8bRHYcXn9vyqGHWo6Y1CWWVCfZKCol5KQpK9kDGo7ZJQEZlwv8Uo3ObAv/r/AcA).
**Explanation:**
```
d     # Check for both values in the (implicit) input-coordinate whether it's non-negative (>=0)
 2β   # Convert this from a binary-list to an integer
   Q  # And check whether it's equal to the (implicit) direction input-integer
      # (after which this is output implicitly)
```
[Answer]
# [Pure Data](https://puredata.info), 65 bytes
```
#X obj 0 0 expr (8*($i1<0)+4*($i2<0)+2*($i1>0)+($i2>0)&1<<$i3)<1;
```
This line can be added to a pure data patch to make an object positioned at `0 0` which takes 3 inputs and produces one output. The first two are the x and y and the last is the direction (range 0 to 3).
Here is an example of how it can be called:
[![enter image description here](https://i.stack.imgur.com/7PRY2.png)](https://i.stack.imgur.com/7PRY2.png)
This ports [my haskell answer](https://codegolf.stackexchange.com/a/198738/56656) in logic, however since arrays are a nightmare in pure-data we use arithmetic and bitwise operations instead. We pack the 4 booleans (ints in pd) into a four bit integer and use `&` to index them.
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), ~~13~~ 9 bytes
```
⁼↨Ｅ²›⁰Ｎ²Ｎ
```
[Try it online!](https://tio.run/##S85ILErOT8z5/z@gKDOvRMO1sDQxp1jDKbE4VcM3sUDDSEfBvSg1sSS1SMNAR8Ezr6C0xK80NwnI1dTU1FEw0sQQtP7/X9dUwVjB6L9uWQ4A "Charcoal – Try It Online") Link is to verbose version of code. Edit: Saved 4 bytes by porting @isaacg’s Pyth answer. Uses the same "move or turn" approach; `-` means move, no output means turn. The directions encode as `y--`, `x--`, `x++`, `y++`. Explanation:
```
   ²        Literal 2
  Ｅ         Map over implicit range
     ⁰      Literal 0
    ›       Is greater than
      Ｎ     Input coordinate
 ↨     ²    Convert from base 2
⁼           Equals
        Ｎ   Input direction
```
]