[Question]
  [
It's a common problem to navigate in a 2D matrix. We've seen it many times and will see again. So let's help future us and develop the shortest solutions to generate all eight possible steps in a 2D matrix.
## Challenge
Your code must output the following 8 pairs of -1,0,1 in any order:
```
(0,1)
(0,-1)
(1,0)
(-1,0)
(1,1)
(1,-1)
(-1,1)
(-1,-1)
```
## Rules
1. There is no input.
2. Output order is not relevant
3. Output is flexible. Pairs of numbers just need to be distinguishable
4. This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so shortest answer in bytes wins
  
[Answer]
# [Octave](https://www.gnu.org/software/octave/), 24 bytes
```
dec2base([0:3,5:8],3)-49
```
[Try it online!](https://tio.run/##y08uSSxL/f8/JTXZKCmxOFUj2sDKWMfUyiJWx1hT18Ty/38A "Octave – Try It Online")
I haven't seen this approach yet.
Creates a list of integers `[0, 1, 2, 3, 5, 6, 7, 8]`, and converts it to ternary, returning a character array:
```
00
01
02
10
12
20
21
22
```
Subtracting `49` (ASCII-value for `1`) from all characters gives a numeric array:
```
-1  -1
-1   0
-1   1
 0  -1
 0   1
 1  -1
 1   0
 1   1
```
[Answer]
# Pure [Bash](https://www.gnu.org/software/bash/) (no external utilities), 36
```
a=({0,-1,1},{0,-1,1})
echo ${a[@]:1}
```
[Try it online!](https://tio.run/##S0oszvj/P9FWo9pAR9dQx7BWB8bQ5EpNzshXUKlOjHaItTKs/f8fAA "Bash – Try It Online")
---
# [Bash](https://www.gnu.org/software/bash/) with Sed, 35
```
printf %s\\n {-1..1},{-1..1}|sed 5d
```
[Try it online!](https://tio.run/##S0oszvj/v6AoM68kTUG1OCYmT6Fa11BPz7BWB0rXFKemKJim/P8PAA "Bash – Try It Online")
[Answer]
# T-SQL, ~~80~~ 78 bytes
```
SELECT-1n INTO t;INSERT t VALUES(0),(1)SELECT*FROM t,t z WHERE t.n<>0OR z.n<>0
```
Creates a (permanent) table **t** containing `(-1,0,1)`, and performs a self-join with a `WHERE` clause that excludes the `0,0` row. The table **t** is not cleaned up by my code, you must drop it yourself.
Sadly nearly twice as long as the boring solution (**44 bytes**), since SQL allows returns in strings:
```
PRINT'0,1
0,-1
1,0
-1,0
1,1
1,-1
-1,1
-1,-1'
```
[Answer]
# [Python 2](https://docs.python.org/2/), 33 bytes
```
i=9;exec"print-i%3-1,i/5;i-=2;"*8
```
[Try it online!](https://tio.run/##K6gsycjPM/r/P9PW0jq1IjVZqaAoM69EN1PVWNdQJ1Pf1DpT19bIWknL4v9/AA "Python 2 – Try It Online")
Dennis saved ~~3~~ 5 bytes, wow. Thanks!
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), ~~8~~ ~~7~~ 6 bytes
```
3p_2ẸƇ
```
[Try it online!](https://tio.run/##y0rNyan8/9@4IN7o4a4dx9r//wcA "Jelly – Try It Online")
My first ever Jelly answer! Much thanks to Dennis for the final piece of the puzzle.
Now, let's see if I can explain it ... lol.
```
3p_2ẸƇ   Main program, takes no input.
3p       Product with Range 3, yields [[1,1], [1,2], [1,3], [2,1], [2,2], ...]
  _2     Decrement twice, vectorizes, yields [[-1,-1], [-1,0], [-1,1], [0,-1], ...]
    ẸƇ   Comb, removes those that contain only falsey values, the [0,0]
         Implicit output
```
*-1 byte thanks to Erik; -1 byte thanks to Mr Xcoder and Dennis*
[Answer]
# [Haskell](https://www.haskell.org/), 22 bytes
```
_:l=mapM(:[1,-1])[0,0]
```
[Try it online!](https://tio.run/##y0gszk7Nyfn/P94qxzY3scBXwyraUEfXMFYz2kDHIPZ/bmJmnm1BUWZeiULO/3/JaTmJ6cX/dZMLCgA "Haskell – Try It Online")
*Laikoni saved 1 byte.*
[Answer]
# [R](https://www.r-project.org/), ~~26~~ 24 bytes
Credits to @JDoe for saving two more bytes with a direct approach:
```
paste(-1:1,-3:5%/%3)[-5]
```
[Try it online!](https://tio.run/##K/r/vyCxuCRVQ9fQylBH19jKVFVf1VgzWtc09v9/AA "R – Try It Online")
The original asnwer:
```
outer(-1:1,-1:1,paste)[-5]
```
[Try it online!](https://tio.run/##K/r/P7@0JLVIQ9fQylAHTBQkFpekakbrmsb@/w8A "R – Try It Online")
Or for 27 bytes
```
sapply(-1:1,paste,-1:1)[-5]
```
[Try it online!](https://tio.run/##K/r/vzixoCCnUkPX0MpQpyCxuCRVB8TUjNY1jf3/HwA "R – Try It Online")
Or for 34 bytes with factors:
```
(gl(3,3,,-1:1):gl(3,1,9,-1:1))[-5]
```
[Try it online!](https://tio.run/##K/r/XyM9R8NYx1hHR9fQylDTCswz1LGEcDWjdU1j//8HAA "R – Try It Online")
This last solution might be the golfiest if the output could be from 1 to 3 rather than from -1 to 1.
See [the other R answer](https://codegolf.stackexchange.com/a/164763/80010) for alternate solutions with `expand.grid` or with `cbind`.
[Answer]
# [Japt](https://github.com/ETHproductions/japt), ~~13~~ ~~12~~ 11 bytes
*Saved a byte thanks to @Shaggy*
```
9ó8_ìJõ é)Å
```
[Try it online!](https://tio.run/##y0osKPn/3/LwZov4w2u8Dm9VOLxS83Dr//@6QQA "Japt – Try It Online") Uses `-R` flag to put each item on its own line.
### Explanation
```
9ó8_ìJõ é)Å
9ó8             Create the range [9, 9+8). [9, 10, ..., 16]
   _            Map each item in this range through this function:
     Jõ é)        Generate the range [-1...1] and rotate to get [1, -1, 0].
    ì             Convert the item to an array of base-3 digits,
                  mapping [0,1,2] to [1,-1,0]. [[-1, 1, 1], [-1, 1,-1], [-1, 1, 0],
                                                [-1,-1, 1], [-1,-1,-1], [-1,-1, 0],
                                                [-1, 0, 1], [-1, 0,-1]]
          Å       Remove the first item (gets rid of the leading -1).
```
[Answer]
# [Japt](https://github.com/ETHproductions/japt) `-Q`, ~~15~~ 13 bytes
I'm sure there's a shorter way, but I liked this approach.
```
##ü80ì3 mÉ ò
##ü80        // Take 14425280
     ì3      // and turn it into an array of base-3 numbers.
        mÉ   // Subtract one from each digit
           ò // and then split them pairwise.
```
Shaved off two bytes thanks to [Shaggy](https://codegolf.stackexchange.com/users/58974/shaggy).
[Try it online!](https://ethproductions.github.io/japt/?v=2.0a0&code=I5Aj/Dgw7DMgbckg8g==&input=LVE=)
[Answer]
# [Perl 6](https://github.com/nxadm/rakudo-pkg), 23 bytes
```
{(1,-1,0 X 1,-1,0)[^8]}
```
[Try it online!](https://tio.run/##K0gtyjH7n1upoJamYPu/WsNQR9dQx0AhQgHC0IyOs4it/V@cWKmQpqFp/R8A "Perl 6 – Try It Online")
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), ~~8~~ 7 bytes
```
2Ý<ãʒĀZ
```
[Try it online!](https://tio.run/##MzBNTDJM/f/f6PBcm8OLT0060hD1/z8A "05AB1E – Try It Online")
**Explanation**
```
2Ý<     # Range of 2 decremented, yields [-1, 0, 1]
   ã    # Cartesian product of the list with itself
    ʒ   # Filter by ...
     ĀZ # Maximum of the truthified values, yields 0 only if both values are 0.
```
-1 byte thanks to Emigna !
[Answer]
# [Husk](https://github.com/barbuz/Husk), ~~7~~ 6 bytes
There are a lot of different ways (the tricky/costly part is getting rid of `[0,0]`), ~~7 bytes is the shortest I could come up~~ thanks to [Leo](https://codegolf.stackexchange.com/users/62393/leo?tab=profile) for pointing out to use decimal conversion (`d`) as a filter:
```
fdπ2ṡ1
```
[Try it online!](https://tio.run/##yygtzv7/Py3lfIPRw50LDf//BwA "Husk – Try It Online")
### Explanation
```
fdπ2ṡ1  -- constant function (expects no arguments)
    ṡ1  -- symmetric range [-n..n]: [-1,0,1]
  π2    -- cartesian power of 2: [[-1,-1],[-1,0],[0,-1],[-1,1],[0,0],[1,-1],[0,1],[1,0],[1,1]]
f       -- filter only elements that are truthy when
 d      -- | decimal conversion (interpret as polynomial and evaluate at x=10)
        -- : [[-1,-1],[-1,0],[0,-1],[-1,1],[1,-1],[0,1],[1,0],[1,1]]
```
---
## Alternative, 7 bytes
```
tπ2ṙ1ṡ1
```
[Try it online!](https://tio.run/##yygtzv7/v@R8g9HDnTMNH@5caPj/PwA "Husk – Try It Online")
### Explanation
```
tπ2ṙ1ṡ1  -- constant function (expects no arguments)
     ṡ1  -- symmetric range [-n..n]: [-1,0,1]
   ṙ1    -- rotate by 1: [0,1,-1]
 π2      -- cartesian power of 2: [[0,0],[0,1],[1,0],[0,-1],[1,1],[-1,0],[1,-1],[-1,1],[-1,-1]]
t        -- tail: [[0,1],[1,0],[0,-1],[1,1],[-1,0],[1,-1],[-1,1],[-1,-1]]
```
[Answer]
# [MATL](https://github.com/lmendo/MATL), 12 bytes
```
9:q4X-3YA49-
```
[Try it online!](https://tio.run/##y00syfn/39Kq0CRC1zjS0cRS9/9/AA "MATL – Try It Online")
Because it's MATL month, here's a MATL port of @Stewie's Octave answer. The sequence [0 1 2 3 5 6 7 8] is generated as the set difference between [0 ... 8] and 4.
[Answer]
# Java 8, ~~83~~ 42 bytes
```
v->"1,1 1,0 1,-1 0,1 0,-1 -1,1 -1,0 -1,-1"
```
-41 bytes thanks to *@AdmBorkBork* by hard-coding..
[Try it online.](https://tio.run/##LU5BCoMwELz3FYunCEbMWdof1IvQS@lhG22JjVHMGijFt6cbFHZgd4aZnQEDyqH7RG3Re7iicb8TgHHULy/UPTTpBGhpMe4NWtwm00HIa2Y3Bo8nJKOhAQdniEFeMlUoUEXFkAqqIoEXmWiZeJmELNa7f16flv1HTEj5I9cQ@8v7A/OjwtdTP5bTSuXMCglXauFWa/OjzRb/)
---
Non hard-coded version as reference (**~~83~~ ~~72~~ ~~70~~ 68 bytes**):
```
v->{for(int i=9;i-->1;)System.out.println(~i%3+1+","+(~(i/3)%3+1));}
```
-11 bytes thanks to *@OlivierGrégoire*.  
-2 bytes creating a port of [*@ETHproductions*'s JavaScript (ES6) answer](https://codegolf.stackexchange.com/a/164797/52210).
[Try it online.](https://tio.run/##LY7BCoMwDIbve4owGLS4OsTTKPoG8yLsMnboqo66WsVWYYi@ehenkBD@hPz/V4tRsLr4eKmFtXATykwHAGVc2VdClpCtEmBsVQGS3NcxUo67GRvLOuGUhAwMJOBHlk5V2xP8B5VcuWIsjTjNv9aVTdgOLux6vGlDFnWKgyg4no8BWYi6xHTVlPLZ8825G14anfeAP0CDeCR3aPF@PAXd0EwoiRm03qlm/wM)
[Answer]
# [R](https://www.r-project.org/), 27 bytes
```
expand.grid(-1:1,-1:1)[-5,]
```
[Try it online!](https://tio.run/##K/r/P7WiIDEvRS@9KDNFQ9fQylAHRGhG65rqxP7/DwA "R – Try It Online")
30 and 35 bytes:
```
cbind(-1:1,rep(-1:1,e=3))[-5,]
expand.grid(rep(list(-1:1),2))[-5,]
```
[Answer]
# JavaScript (ES6)
Two alternate methods, both longer than hardcoding.
## 49 bytes
```
_=>[...'11202200'].map((n,i,a)=>[~-n,~-a[i+3&7]])
```
[Try it online!](https://tio.run/##y0osSyxOLsosKNHNy09J/Z9m@z/e1i5aT09P3dDQyMDIyMBAPVYvN7FAQyNPJ1MnURMoWaebp1OnmxidqW2sZh4bq/k/OT@vOD8nVS8nP10jTUNT8z8A "JavaScript (Node.js) – Try It Online")
## 51 bytes
```
f=(n=1679887e3)=>n?[n%4-1,~-(n/4%4)]+' '+f(n>>4):''
```
[Try it online!](https://tio.run/##y0osSyxOLsosKNHNy09J/f8/zVYjz9bQzNzSwsI81VjT1i7PPjpP1UTXUKdOVyNP30TVRDNWW11BXTtNI8/OzkTTSl39f3J@XnF@TqpeTn66RpqGpuZ/AA "JavaScript (Node.js) – Try It Online")
[Answer]
# [Haskell](https://www.haskell.org/), ~~28~~ 27 bytes
```
tail.mapM id$[0,1,-1]<$"ao"
```
[Try it online!](https://tio.run/##y0gszk7NyfmfZhvzvyQxM0cvN7HAVyEzRSXaQMdQR9cw1kZFKTFf6X9uYmaebUFRZl6JQtr/f8lpOYnpxf91kwsKAA "Haskell – Try It Online")
[Answer]
# [J](http://jsoftware.com/), ~~18~~ 16 bytes
```
echo}.,{;~0 1 _1
```
[Try it online!](https://tio.run/##y/r/PzU5I79WT6faus5AwVAh3vD/fwA)
[Answer]
# [PowerShell](https://github.com/TryItOnline/TioSetup/wiki/Powershell), 41 bytes
```
(1..-1|%{$i=$_;1..-1|%{"$i,$_"}})-ne'0,0'
```
[Try it online!](https://tio.run/##K8gvTy0qzkjNyfn/X8NQT0/XsEa1WiXTViXeGsZTUsnUUYlXqq3V1M1LVTfQMVD//x8A "PowerShell – Try It Online")
Double-for loop over the range `1..-1`, with a `-n`ot`e`quals at the end to pull out the extraneous `0,0` entry. They're each individually left on the pipeline and implicit `Write-output` at program completion gives us newlines for free.
---
Sadly, just the barebones string output is two bytes shorter:
```
'1,1
1,0
1,-1
0,1
0,-1
-1,1
-1,0
-1,-1'
```
But that's boring.
[Answer]
# [Python 2](https://docs.python.org/2/), 39 bytes
```
n=6;exec'n+=~(n==2);print n/3,n%3-1;'*8
```
[Try it online!](https://tio.run/##K6gsycjPM/r/P8/WzDq1IjVZPU/btk4jz9bWSNO6oCgzr0QhT99YJ0/VWNfQWl3L4v9/AA "Python 2 – Try It Online")
[Answer]
# [Haskell](https://www.haskell.org/), 27 bytes
```
tail$(,)<$>t<*>t
t=[0,1,-1]
```
[Try it online!](https://tio.run/##y0gszk7Nyfmfm5iZp2CrUFCUmVeioKIQ878kMTNHRUNH00bFrsRGy66Eq8Q22kDHUEfXMPb//3/JaTmJ6cX/dSOcAwIA "Haskell – Try It Online")
The output is `[(0,1),(0,-1),(1,0),(1,1),(1,-1),(-1,0),(-1,1),(-1,-1)]`.
[Answer]
# [CJam](https://sourceforge.net/p/cjam), 13 bytes
```
3,:(2m*{2b},`
```
[Try it online!](https://tio.run/##S85KzP3/31jHSsMoV6vaKKlWJ@H/fwA "CJam – Try It Online")
## Explanation
```
3,    e# Range [0,3):       [0 1 2]
:(    e# Decrement each:    [-1 0 1]
2m*   e# Cartesian square:  [[-1 -1] [-1 0] [-1 1] [0 -1] [0 0] [0 1] [1 -1] [1 0] [1 1]]
{     e# Filter by
 2b   e#   conversion to binary:
},    e#                    [[-1 -1] [-1 0] [-1 1] [0 -1] [0 1] [1 -1] [1 0] [1 1]]
`     e# Stringify:         "[[-1 -1] [-1 0] [-1 1] [0 -1] [0 1] [1 -1] [1 0] [1 1]]"
```
[Answer]
# [Befunge-93](https://github.com/catseye/Befunge-93), 24 bytes
```
11#v91090~9~19~<
9.._@#,
```
[Try it online!](https://tio.run/##S0pNK81LT/3/39BQuczS0MDSoM6yztCyzobLUk8v3kFZ5/9/AA "Befunge-93 – Try It Online")
I feel like this challenge is missing answers from 2D languages, even if most don't move diagonally. This outputs space separated numbers, each pair separated by tabs.
[Answer]
# [F# (Mono)](http://www.mono-project.com/), 54 bytes
```
let f=Seq.where((<>)(0,0))(Seq.allPairs[-1..1][-1..1])
```
[Try it online!](https://tio.run/##SyvWzc3Py///Pye1RCHNNji1UK88I7UoVUPDxk5Tw0DHQFNTAySYmJMTkJhZVByta6inZxgLpTT/pynU2CmAFGSWpBYpaBQUZeaVpOUpKKk6Kmn@BwA "F# (Mono) – Try It Online")
44 bytes - thanks to Laikoni:
```
let f=Seq.tail(Seq.allPairs[0;-1;1][0;-1;1])
```
[Answer]
# [Brachylog](https://github.com/JCumin/Brachylog), 8 bytes
```
Ċ{ṡᵐ≜}ᶠb
```
[Try it online!](https://tio.run/##ASEA3v9icmFjaHlsb2cy///EinvhuaHhtZDiiZx94bagYv///1o "Brachylog – Try It Online")
### Explanation
```
Ċ           Couple: take a list of two elements [A,B]
 {   }ᶠ     Find all…
    ≜         …possible values of…
  ṡᵐ          …signs of A and B
       b    Behead: remove the first one which is [0,0]
```
[Answer]
## [Perl 5](https://www.perl.org/), 31 bytes
```
map/1/&&say,<{-1,0,1},{-1,0,1}>
```
[Try it online!](https://tio.run/##K0gtyjH9/z83sUDfUF9NrTixUsemWtdQx0DHsFYHxrD7//9ffkFJZn5e8X9dX1M9A0MDAA "Perl 5 – Try It Online")
[Answer]
## [Bash](https://www.gnu.org/software/bash/), 30 bytes
```
echo "
"{-1..1},{-1..1}|grep 1
```
[Try it online!](https://tio.run/##S0oszvj/PzU5I19BiUupWtdQT8@wVgdK16QXpRYoGP7/DwA "Bash – Try It Online")
Prints a trailing space on each line but the last. (Thanks to [@Neil](https://codegolf.stackexchange.com/users/17602/neil) - this originally printed a leading space, but a trailing space is better as per their comment)
[Answer]
# [MATL](https://github.com/lmendo/MATL), 12 bytes
```
3:qq2Z^[]5Y(
```
[Try it at MATL Online!](https://matl.io/?code=3%3Aqq2Z%5E%5B%5D5Y%28&inputs=&version=20.9.1)
My first ever serious MATL answer! Thanks a lot to [Luis Mendo](https://codegolf.stackexchange.com/users/36398/luis-mendo), [Sanchises](https://codegolf.stackexchange.com/users/32352/sanchises) and [DJMcMayhem](https://codegolf.stackexchange.com/users/31716/djmcmayhem) for the help.
### How it works
```
3:qq2Z^[]5Y( – Full program. Outputs to STDOUT.
3:           – Range 3. Push [1 2 3] to the stack.
  qq         – Decrement by 2. Yields [-1 0 1].
    2Z^      – Cartesian power of 2.
         5Y( – Replace the row at index 5 with...
       []    – An empty vector.
```
[Answer]
## Batch, 77 bytes
```
@for %%x in (-1 0 1)do @for %%y in (-1 0 1)do @if not %%x%%y==00 echo %%x %%y
```
63 bytes if a nonstandard separator is allowed:
```
@for %%x in (-1/-1 -1/0 -1/1 0/-1 0/1 1/-1 1/0 1/1)do @echo %%x
```
[Answer]
# Pyth, ~~11~~ 9 bytes
```
t^+U2_1 2
```
[Try it here](http://pyth.herokuapp.com/?code=t%5E%2BU2_1+2&debug=0)
### Explanation
```
t^+U2_1 2
  +U2_1     [0, 1, -1]
 ^      2   Product with itself.
t           Exclude the first.
```
Equivalently, we could use `t*J+U2_1J`, but that's not any shorter.
]