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
- There is no input.
- Output order is not relevant
- Output is flexible. Pairs of numbers just need to be distinguishable
- This is code-golf, so shortest answer in bytes wins
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.6231@Adám Yes, use anything while pairs of numbers are distinguishable – Dead Possum – 2018-05-14T15:59:56.407
@DeadPossum APL represents
0+1i
as0J1
. – Adám – 2018-05-14T16:52:14.0701@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.987Whoops, 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