Orthodiagonal steps

26

3

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 , so shortest answer in bytes wins

Dead Possum

Posted 2018-05-14T14:13:12.267

Reputation: 3 256

I'm 100% sure that this is a duplicate, but I'm having trouble coming up with the right search terms to find the old challenge... – Martin Ender – 2018-05-14T14:27:07.147

2@MartinEnder I was 99% sure about that too, but didn't find any either. So I've put it in sandbox for a few days, but noone commented about duplicate. – Dead Possum – 2018-05-14T14:28:56.397

I also remember there being an old challenge that was either exactly this or this in large part. – xnor – 2018-05-14T15:03:38.870

4Because of the flexible output, there turns out to be an interesting Kolmogorov complexity flavour to this one. Some languages will find it harder than to do better than just hard coding the output. Should this tag be added? – ngm – 2018-05-14T15:08:54.650

May we output a list of complex numbers, [0+i,0-i,1,-1,1+i…? – Adám – 2018-05-14T15:44:20.113

@Adám I believe, there would be interesting answers with complex numbers, and I want to allow it, but lots of people already answered with pairs of numbers, as stated in question, so I'd say, that it would be discouraging to them, so no. – Dead Possum – 2018-05-14T15:52:48.300

@ngm Hardcoding answer is rather boring solution, but it is still a solution, no doubt. Though I don't want to add this tag to encourage such solutions. – Dead Possum – 2018-05-14T15:54:44.617

@DeadPossum May we use J to separate the coordinates instead of , e.g. 0J1 instead of (0,1)? – Adám – 2018-05-14T15:58:57.623

1@Adám Yes, use anything while pairs of numbers are distinguishable – Dead Possum – 2018-05-14T15:59:56.407

@DeadPossum APL represents 0+1i as 0J1. – Adám – 2018-05-14T16:52:14.070

1@Adám But what about (1 + 0i) ? – Dead Possum – 2018-05-14T17:48:51.047

@DeadPossum Differs between APL systems. Maybe some do display an imaginary part on all members of a list if at least one member has an imaginary part. I'm not sure. – Adám – 2018-05-14T18:00:53.273

@Adám Well, if both parts are displayed explicitly, it'll borderline-ish pass as valid answer – Dead Possum – 2018-05-14T19:30:56.230

1@DeadPossum Wouldn't that be unfair to other languages which happen to have a different display format for complex numbers? (Read: allow returning a list of complex numbers!) – Adám – 2018-05-14T20:01:32.840

1@Adám True. No complex numbers. No hesitations. – Dead Possum – 2018-05-14T20:55:48.353

8

This is an exact duplicate of 8 adjacent squares, one of the first code golfs I ever did.

– isaacg – 2018-05-15T18:17:47.987

Whoops, I forgot I got a hammer two days ago... I voted (and accidentally hammered) close the other one as a dupe of this one. Feel free to undo it, but I think it's the best solution. – Stewie Griffin – 2018-05-15T19:15:54.917

Answers

19

Octave, 24 bytes

dec2base([0:3,5:8],3)-49

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

Stewie Griffin

Posted 2018-05-14T14:13:12.267

Reputation: 43 471

9

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'

BradC

Posted 2018-05-14T14:13:12.267

Reputation: 6 099

I don't know T-SQL so well: can you use just WHERE t.n OR z.n? (You can in some but not all SQL dialects.) – msh210 – 2018-05-14T23:19:06.837

@msh210 Good idea, I tried it but it doesn't seem to work on MS SQL Server. I get the error: An expression of non-boolean type specified in a context where a condition is expected – BradC – 2018-05-15T13:22:05.117

1You can remove the spaces around the * – Razvan Socol – 2018-07-11T04:26:59.313

8

Pure Bash (no external utilities), 36

a=({0,-1,1},{0,-1,1})
echo ${a[@]:1}

Try it online!


Bash with Sed, 35

printf %s\\n {-1..1},{-1..1}|sed 5d

Try it online!

Digital Trauma

Posted 2018-05-14T14:13:12.267

Reputation: 64 644

Alternatively using cut for 36 bytes as well. – ბიმო – 2018-05-14T15:43:45.443

33 bytes for bash+sed (despite how boring it is), echo {-1..1},{-1..1}|sed s/0,0.//

– user41805 – 2018-05-14T18:01:50.110

printf %s\\n {-1..1},{-1..1}|grep 1 is also 35. – Neil – 2018-05-14T18:07:29.033

7

R, 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!

The original asnwer:

outer(-1:1,-1:1,paste)[-5]

Try it online!

Or for 27 bytes

sapply(-1:1,paste,-1:1)[-5]

Try it online!

Or for 34 bytes with factors:

(gl(3,3,,-1:1):gl(3,1,9,-1:1))[-5]

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 for alternate solutions with expand.grid or with cbind.

JayCe

Posted 2018-05-14T14:13:12.267

Reputation: 2 655

huh, nice use of the flexible output format! – Giuseppe – 2018-05-14T14:50:44.427

2This one is better than mine because of how ultimately useless it is :) – ngm – 2018-05-14T14:52:46.057

@Giuseppe Originally I tried c which did not make sense inside a matrix so I switched to paste and the original output format... – JayCe – 2018-05-14T16:02:16.070

24 bytes with paste – J.Doe – 2018-09-27T09:24:30.487

1@J.Doe you rock! – JayCe – 2018-09-27T13:52:18.950

7

Jelly, 8 7 6 bytes

3p_2ẸƇ

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

AdmBorkBork

Posted 2018-05-14T14:13:12.267

Reputation: 41 581

1Alterate answer based on this approach: 3p3_2ẸƇ – Mr. Xcoder – 2018-05-14T20:19:14.417

@Mr.Xcoder You can drop the second 3. – Dennis – 2018-05-15T01:52:52.587

@Dennis Oh, indeed. In this case, Adm can update with the 6-byter :) – Mr. Xcoder – 2018-05-15T04:08:54.247

7

Python 2, 33 bytes

i=9;exec"print-i%3-1,i/5;i-=2;"*8

Try it online!

Dennis saved 3 5 bytes, wow. Thanks!

Lynn

Posted 2018-05-14T14:13:12.267

Reputation: 55 648

7

Haskell, 22 bytes

_:l=mapM(:[1,-1])[0,0]

Try it online!

Laikoni saved 1 byte.

xnor

Posted 2018-05-14T14:13:12.267

Reputation: 115 687

_:l=mapM(:[1,-1])[0,0] saves a byte. (Taken from isaacg's answer to the earlier challenge). – Laikoni – 2018-05-16T09:05:53.307

@Laikoni So I had considered that and thought that would make it a snippet (as many answers to the old challenge were). But combining this meta post with the rule that functions can be defined indirectly, so this seems to be OK. Thanks for the suggestion.

– xnor – 2018-05-19T00:28:00.087

6

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.

Try it online!

Nit

Posted 2018-05-14T14:13:12.267

Reputation: 2 667

6

Japt, 13 12 11 bytes

Saved a byte thanks to @Shaggy

9ó8_ìJõ é)Å

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).

ETHproductions

Posted 2018-05-14T14:13:12.267

Reputation: 47 880

5

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.


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.

Try it online.

Kevin Cruijssen

Posted 2018-05-14T14:13:12.267

Reputation: 67 575

Non-hardcoded answer in 72 bytes: v->{for(int i=9;i-->0;)if(i!=4)System.out.println((i/3-1)+","+(i%3-1));}. – Olivier Grégoire – 2018-05-17T12:40:30.377

@OlivierGrégoire Thanks, added (and golfed by 2 more bytes). – Kevin Cruijssen – 2018-05-17T12:47:43.393

5

Perl 6, 23 bytes

{(1,-1,0 X 1,-1,0)[^8]}

Try it online!

nwellnhof

Posted 2018-05-14T14:13:12.267

Reputation: 10 037

5

05AB1E, 8 7 bytes

2Ý<ãʒĀZ

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 !

Kaldo

Posted 2018-05-14T14:13:12.267

Reputation: 1 135

Dang, you beat me to it. Had the same start (2Ý<ã), but was figuring out how to remove the middle element of the list of pairs.. Hadn't thought about sort by absolute value and removing the first.. +1 from me. – Kevin Cruijssen – 2018-05-14T15:33:03.553

2Use ʒĀZ to save 1 – Emigna – 2018-05-15T05:52:39.157

@Emigna Thanks for making me understand the difference between the regular and the 05AB1IE version of the truthified command :-) – Kaldo – 2018-05-15T07:38:59.523

5

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 for pointing out to use decimal conversion (d) as a filter:

fdπ2ṡ1

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!

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]]

ბიმო

Posted 2018-05-14T14:13:12.267

Reputation: 15 345

1

Another 7 byte alternative tπ2↑3İZ.

– Laikoni – 2018-05-14T22:13:31.070

2

You can save one byte by filtering the lists based on their decimal conversion Try it online!

– Leo – 2018-05-15T04:13:58.057

5

MATL, 12 bytes

9:q4X-3YA49-

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.

Sanchises

Posted 2018-05-14T14:13:12.267

Reputation: 8 530

4

R, 27 bytes

expand.grid(-1:1,-1:1)[-5,]

Try it online!

30 and 35 bytes:

cbind(-1:1,rep(-1:1,e=3))[-5,]
expand.grid(rep(list(-1:1),2))[-5,]

ngm

Posted 2018-05-14T14:13:12.267

Reputation: 3 974

Some funky looking output, I like it :D Good job – Dead Possum – 2018-05-14T14:37:53.790

expand.grid(-1:1,-1:1)[-5,] is 27 bytes. – Giuseppe – 2018-05-14T14:46:02.117

4

Haskell, 28 27 bytes

tail.mapM id$[0,1,-1]<$"ao"

Try it online!

Angs

Posted 2018-05-14T14:13:12.267

Reputation: 4 825

4

JavaScript (ES6)

Two alternate methods, both longer than hardcoding.

49 bytes

_=>[...'11202200'].map((n,i,a)=>[~-n,~-a[i+3&7]])

Try it online!

51 bytes

f=(n=1679887e3)=>n?[n%4-1,~-(n/4%4)]+' '+f(n>>4):''

Try it online!

Arnauld

Posted 2018-05-14T14:13:12.267

Reputation: 111 334

4

Haskell, 27 bytes

tail$(,)<$>t<*>t
t=[0,1,-1]

Try it online!

The output is [(0,1),(0,-1),(1,0),(1,1),(1,-1),(-1,0),(-1,1),(-1,-1)].

Laikoni

Posted 2018-05-14T14:13:12.267

Reputation: 23 676

3

PowerShell, 41 bytes

(1..-1|%{$i=$_;1..-1|%{"$i,$_"}})-ne'0,0'

Try it online!

Double-for loop over the range 1..-1, with a -notequals 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.

AdmBorkBork

Posted 2018-05-14T14:13:12.267

Reputation: 41 581

3

Perl 5, 31 bytes

map/1/&&say,<{-1,0,1},{-1,0,1}>

Try it online!

Dom Hastings

Posted 2018-05-14T14:13:12.267

Reputation: 16 415

Would -1..1 work in the glob? – msh210 – 2018-05-14T23:11:41.530

@msh210 Unfortunately not... I did experiment with it, and it works in bash, but not in Perl :(

– Dom Hastings – 2018-05-15T07:26:35.030

3

CJam, 13 bytes

3,:(2m*{2b},`

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]]"

Esolanging Fruit

Posted 2018-05-14T14:13:12.267

Reputation: 13 542

3

Python 2, 39 bytes

n=6;exec'n+=~(n==2);print n/3,n%3-1;'*8

Try it online!

Dennis

Posted 2018-05-14T14:13:12.267

Reputation: 196 637

3

J, 18 16 bytes

echo}.,{;~0 1 _1

Try it online!

FrownyFrog

Posted 2018-05-14T14:13:12.267

Reputation: 3 112

Why minus is displayed as underscore in TIO? – Dead Possum – 2018-05-14T18:11:45.027

18 bytes alternative: echo }.>,{;~0 1 _1 TIO

– Galen Ivanov – 2018-05-14T18:15:26.727

@Dead Possum Negative numbers are displayed with an underscore in J – Galen Ivanov – 2018-05-14T18:20:26.700

1Yes, 17 :) echo}.>,{;~0 1 _1 – Galen Ivanov – 2018-05-14T18:21:47.707

2Is echo needed? – cole – 2018-05-14T20:20:35.580

agree with @cole, it seems like snippets should be allowed on "output only" challenges in J, but not totally clear on the rules – Jonah – 2018-06-13T03:06:48.777

3

F# (Mono), 54 bytes

let f=Seq.where((<>)(0,0))(Seq.allPairs[-1..1][-1..1])

Try it online!

44 bytes - thanks to Laikoni:

let f=Seq.tail(Seq.allPairs[0;-1;1][0;-1;1])

Henrik Hansen

Posted 2018-05-14T14:13:12.267

Reputation: 191

1

44 bytes by having (0,0) be the first element and calling Seq.tail: Try it online!

– Laikoni – 2018-05-14T22:07:17.733

3

Befunge-93, 24 bytes

11#v91090~9~19~<
9.._@#,

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.

Jo King

Posted 2018-05-14T14:13:12.267

Reputation: 38 234

3

Brachylog, 8 bytes

Ċ{ṡᵐ≜}ᶠb

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]

Fatalize

Posted 2018-05-14T14:13:12.267

Reputation: 32 976

3

Bash, 30 bytes

echo "
"{-1..1},{-1..1}|grep 1

Try it online!

Prints a trailing space on each line but the last. (Thanks to @Neil - this originally printed a leading space, but a trailing space is better as per their comment)

Dom Hastings

Posted 2018-05-14T14:13:12.267

Reputation: 16 415

I guess you could print a trailing space on all but the last line as an alternative. – Neil – 2018-05-20T10:35:41.420

3

MATL, 12 bytes

3:qq2Z^[]5Y(

Try it at MATL Online!

My first ever serious MATL answer! Thanks a lot to Luis Mendo, Sanchises and 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.

Mr. Xcoder

Posted 2018-05-14T14:13:12.267

Reputation: 39 774

2

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

Neil

Posted 2018-05-14T14:13:12.267

Reputation: 95 035

2

Jelly, 6 bytes

;Ø+p`Ḋ

Try it online!

-1 thanks to Dennis.

Erik the Outgolfer

Posted 2018-05-14T14:13:12.267

Reputation: 38 134

2

Pyth, 11 9 bytes

t^+U2_1 2

Try it here

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.

user48543

Posted 2018-05-14T14:13:12.267

Reputation:

2

JavaScript (ES6), 45 bytes

f=(n=8)=>n?[...f(n-1),[1+~n%3,1+~(n/3)%3]]:[]

Try it online!

Another alternative to hardcoding, still not as short though...

ETHproductions

Posted 2018-05-14T14:13:12.267

Reputation: 47 880

2

Japt, 14 13 bytes

[J1T]ê à2 s1J

Try it online!

Oliver

Posted 2018-05-14T14:13:12.267

Reputation: 7 160

2

Stax, 10 bytes

τÄêdD┘│çû╢

Run and debug it

Explanation (unpacked):

1:r2|^{|af|u Full program
1:r          Push [-1, 0, 1]
   2|^       Join with self
   c|*        Alternative: copy and join
      {  f   Filter:
       |a      Any truthy (not 0)?
          |u Representation

wastl

Posted 2018-05-14T14:13:12.267

Reputation: 3 089

2

PHP, 79, 76, 73 Bytes

76 Bytes thanks to Dom Hastings

Try it online (79 Bytes) using base 16 (Original answer)

Try it online (77 Bytes) using base 36

Try it online (73 Bytes) using base 36

Tried to avoid any kind of loop

<?=strtr(chunk_split(base_convert("18qfremyq6",36,4),3,"
"),[2=>-1,',']);
//as the starting index is 2, next will be 3, no need for 3=>','

Output

1,0
-1,0
1,1
1,-1
-1,1
-1,-1
0,1
0,-1

Explanation

Basically "72c75eb6e34e" 18qfremyq6 is the base 16 36 representation of a base 4 number 130230131132231232031032, every 3 represents a "," and 2 a -1

Chunk split, adds a line break every 3 characters.

Shorter with an output without the comma, 79 Bytes

<?=strtr(chunk_split(base_convert("10fcb5c",16,3),2,"
"),[2=>-1]);

Output

10
-10
11
1-1
-11
-1-1
01
0-1

Francisco Hahn

Posted 2018-05-14T14:13:12.267

Reputation: 591

2

or this can be done with 37 bytes.

– Francisco Hahn – 2018-05-14T20:54:23.757

2Yeah... I did think hard-coding would be smaller, but programatically is more interesting, right? :) – Dom Hastings – 2018-05-15T07:27:07.040

of couse, far more interesting :-D – Francisco Hahn – 2018-05-15T13:37:08.953

2

Gaia, 8 bytes

3…(¦:×ỵ⁈

Try it online!

This generates the list in this order:

[[-1 -1] [-1 0] [-1 1] [0 -1] [0 1] [1 -1] [1 0] [1 1]]

Explanation

3…(¦:×ỵ⁈ – Full program. Outputs to STDOUT.
3…       – Push [0 1 2] to the stack.
  (¦     – Decrement each; yields [-1 0 1].
    :    – Duplicate.
     ×   – Cartesian product.
       ⁈ – Filter-reject those that:
      ỵ  – Have no truthy element.

An alternative to this would be 3…(¦2*ỵ⁈.

Mr. Xcoder

Posted 2018-05-14T14:13:12.267

Reputation: 39 774

2

Japt, 9 7 bytes

4 Japt solutions to one challenge; that has to be a first :)

Jõ ï fd

Test it


Original, 9 bytes

4#ô²ìJõ)ò

Test it


Explanation

Using the number Nit found for his solution (14425280) as a starting point, I converted it to base-3, split it to an array of 2 character strings and then tested each permutation to see if any of them produced a perfect square or cube when rejoined to a string and converted back to base-10. That gave me the perfect squares 15366400, 18011536 & 18421264 and, of those, only 18011536 had a square root that would allow me to save a byte thanks to Japt's trick of using # to build numbers, that being 4244.

4#ô           :4244
   ²          :Square
     Jõ       :Array [-1,0,1]
    ì  )      :Convert to a digit array in that base
        ò     :Split on every second element

Shaggy

Posted 2018-05-14T14:13:12.267

Reputation: 24 623

2

Ruby, 40 bytes

([*-1..1]*2).permutation(2).uniq-[[0,0]]

Try it online!

Jérémie Bonal

Posted 2018-05-14T14:13:12.267

Reputation: 71

1Could you add a TIO link? Also I've never used Ruby yet, but i think this also outputs (0, 0), which isn't a valid step. – Adyrem – 2018-05-15T11:40:34.273

Oh yeah I completely missed the [0, 0]. I adjusted and added a TiO link. Thanks for catching that! – Jérémie Bonal – 2018-05-15T15:55:57.390

1

K (ngn/k), 15 bytes

{(+1-!x#3)^,&x}

Try it online!

 x:2 / for testing
 x#3 / that many 3s
3 3
 !x#3 / all vectors of 0 1 2 as the columns of a matrix
(0 0 0 1 1 1 2 2 2
 0 1 2 0 1 2 0 1 2)
 +!x#3 / transpose
(0 0
 0 1
 0 2
 1 0
 1 1
 1 2
 2 0
 2 1
 2 2)
 &x / that many 0s
0 0
 (+!x#3)^,&x / remove the all-zero vector
(0 1
 0 2
 1 0
 1 1
 1 2
 2 0
 2 1
 2 2)

ngn

Posted 2018-05-14T14:13:12.267

Reputation: 11 449

1

Wolfram Language (Mathematica), 29 bytes

Print@Rest@Tuples[{0,1,-1},2]

Try it online!

alephalpha

Posted 2018-05-14T14:13:12.267

Reputation: 23 988

1

JavaScript (Node.js), 42 bytes

_=>`1,1
1,0
1,-1
0,1
0,-1
-1,1
-1,0
-1,-1`

Try it online!

Explanation :

Does nothing basically no input and prints the string separated by new lines using string literal.

Muhammad Salman

Posted 2018-05-14T14:13:12.267

Reputation: 2 361

1

Retina, 24 bytes

K`_ _
_
_$"0
+0`_
1$%"-1

Try it online!

TwiNight

Posted 2018-05-14T14:13:12.267

Reputation: 4 187

1

GolfScript, 26 19 18 bytes

9,[4]-{.3/(\3%(n}/

Try it online!

My first GolfScript submission, any help is appreciated! Outputs one element per line, and removes the 0, 0 element.

For nicer printing, I found this 20 byte solution:

9,[4]-{[.3/(\3%(]p}%

which prints one array per line.

maxb

Posted 2018-05-14T14:13:12.267

Reputation: 5 754

1

brainfuck, 86 bytes

+[[<+>->->>---<<<]>]>---.>.<.>.<-.+.>.-.<-.>.+.<.>..<.+.>..<-.>.<+.>.<-.>.-.<.>.<+.>+.

Try it online!

Prints pairs of numbers separated by commas.

Jo King

Posted 2018-05-14T14:13:12.267

Reputation: 38 234

1

JavaScript (Most browsers), 42 40 bytes

for(x=9;x;)--x-4&&alert([~(-x/3),x%3-1])

Only works in DevTools in browsers. As per New users' guides to golfing rules in specific languages this should be valid (Full browser JS program).

If the one above is anyway considered a snippet, then 47 45 bytes:

_=>{for(x=9;x;)--x-4&&alert([~(-x/3),x%3-1])}

Shieru Asakoto

Posted 2018-05-14T14:13:12.267

Reputation: 4 445

1

Whitespace, 219 bytes

[S S S T    T   N
_Push_3][S S T  T   N
_Push_-1][S S S N
_Push_0][S S S T    T   N
_Push_3][S S T  T   N
_Push_-1][S S S T   N
_Push_1][S S S T    T   N
_Push_3][S S S N
_Push_0][S S S T    T   N
_Push_3][S S T  T   N
_Push_-1][S S S T   N
_Push_1][S S S T    T   N
_Push_3][S S T  T   N
_Push_-1][S S S N
_Push_0][S S S T    T   N
_Push_3][S S S T    N
_Push_1][S S S T    T   N
_Push_3][S S S N
_Push_0][S S S T    T   N
_Push_3][S S S T    N
_Push_1][S S S T    S N
_Push_2][S S S N
_Push_0][S S S T    T   N
_Push_3][S S T  T   N
_Push_-1][S S S T   N
_Push_1][S S S T    S N
_Push_2][S S S N
_Push_0][S S S T    T   N
_Push_3][S S S T    N
_Push_1][S S S T    T   N
_Push_3][S S T  T   N
_Push_-1][S S S N
_Push_0][S S S T    S N
_Push_2][S S S T    N
_Push_1][S S S T    T   N
_Push_3][S S S N
_Push_0][S S S T    S N
_Push_2][N
S S N
_Create_Label_LOOP][S S S T S T T   T   S N
_Push_46][T S S S _Add_top_two][T   N
S S _Print_as_character][N
S N
N
_Jump_to_Label_LOOP]

Letters S (space), T (tab), and N (new-line) added as highlighting only.
[..._some_action] added as explanation only.

Try it online (with raw spaces, tabs and new-lines only).

Prints with a . delimiter between each number, and / between each pair of numbers. Since the codepoints of both . and / are between - and 01, these are the shortest delimiters to use with this approach.

Uses this Whitespace tip of mine to print the output. The optimal constant 46 is generated by this Java program.

NOTE: Hard-coded with tab and newline delimiters (since their codepoints are pretty short, being 9 and 10 respectively) would be 332 bytes instead.

Kevin Cruijssen

Posted 2018-05-14T14:13:12.267

Reputation: 67 575

0

Tcl, 44 bytes

puts "-1 -1
0 -1
1 -1
-1 0
1 0
-1 1
0 1
1 1"

Try it online!


Tcl, 77 bytes

set j -1
time {set i -2
time {puts [expr [incr i]|$j?"$i $j":""]} 3
incr j} 3

Try it online!

sergiol

Posted 2018-05-14T14:13:12.267

Reputation: 3 055

0

TI-Basic, 32 bytes

For(A,-1,1
For(B,-1,1
If A≠2B
Disp A,B,"
End
End

Prints pairs as two lines, separated by empty lines.

TI-Basic is a tokenized language, all tokens used here are one-byte.

Explanation:

For(A,-1,1 # First number from -1 to 1 (inclusive)
For(B,-1,1 # Second number from -1 to 1 (inclusive)
If A≠2B    # If the pair is not 0,0
Disp A,B," # Print the first number, then the second, then
           # an empty string (each on its own line)
End        # End second number loop
End        # End first number loop

Output

-1
-1

-1
0

-1
1

0
-1

0
1

1
-1

1
0

1
1

pizzapants184

Posted 2018-05-14T14:13:12.267

Reputation: 3 174

0

Yabasic, 49 bytes

An anonymous function that takes no input and outputs to the console.

For i=-1To 1
For j=-1To 1
If i Or j?i,j
Next
Next

Try it online!

Output

-1 -1
-1 0
-1 1
0 -1
0 1
1 -1
1 0
1 1

Taylor Scott

Posted 2018-05-14T14:13:12.267

Reputation: 6 709

0

VBA, 66 bytes

An anonymous function that takes no input and outputs to the console.

For i=-1To 1:For j=-1To 1:?IIf(i Or j,i &" "&j &vbCr,"");:Next j,i

Output

-1 -1
-1 0
-1 1
0 -1
0 1
1 -1
1 0
1 1

Taylor Scott

Posted 2018-05-14T14:13:12.267

Reputation: 6 709

0

Ruby, 31 bytes

p (w=*-1..1).product(w)-[[0,0]]

Try it online!

G B

Posted 2018-05-14T14:13:12.267

Reputation: 11 099

0

Julia 0.6, 24 bytes

[(A=[0:3;5:8])%3 A÷3]-1

Try it online!

Generate [0,1,2,0,2,0,1,2] in the first column and [0,0,0,1,1,2,2,2] in the second (excluding 4%3 and 4÷3 to avoid 0 0), then subtract 1 from all the values.

Other methods I tried:

[(i,j)for i=-1:1,j=-1:1 if i|j!=0]

[[s...].-'1'for s=base.(3,[0:3;5:8],2)] (based on Stewie Griffin's Octave solution)

[(i,j)for i=-1:1,j=-1:1][(1:9).!=5]

sundar - Reinstate Monica

Posted 2018-05-14T14:13:12.267

Reputation: 5 296

0

MathGolf, 7 5 bytes

1╤╫■╞

-2 bytes by porting @ბიმო's second Husk answer, so make sure to upvote him!

Try it online.

Explanation:

1╤     # Push list [-1,0,1] (push 1; pop and push a list in the range [-n,n])
  ╫    # Rotate it once towards the left: [0,1,-1]
   ■   # Take the cartesian product with itself, creating all possible pairs
    ╞  # Discard the first item of this list (the [0,0] pair)
       # (after which the entire stack joined together is output implicitly)

Kevin Cruijssen

Posted 2018-05-14T14:13:12.267

Reputation: 67 575

0

05AB1E, 6 bytes

T®šã¨

Port of @ბიმო's second Husk answer, so make sure to upvote him!

Try it online.

Explanation:

T      # Push 10
 ®š    # Prepend -1 as list: [-1,1,0]
   ã   # Take the cartesian product of this list with itself, generating all pairs
    ¨  # Remove the last one, which is the [0,0]
       # (after which the result is output implicitly)

Kevin Cruijssen

Posted 2018-05-14T14:13:12.267

Reputation: 67 575