What's the point?
Jelly, 14 bytes
Ṡḅ3ị“Y4X13X2YO
Try it online!
How it works
Ṡḅ3ị“Y4X13X2YO Main link. Input: [x, y]
Ṡ Apply the sign function to both coordinates.
ḅ3 Convert the resulting pair from base 3 to integer.
Because of how base conversion is implemented in Jelly, this maps
[a, b] to (3a + b), even if a and b aren't valid ternary digits.
Therefore:
[0, 1] -> 1
[1, -1] -> 2
[1, 0] -> 3
[1, 1] -> 4
[-1, -1] -> -4
[-1, 0] -> -3
[-1, 1] -> -2
[0, -1] -> -1
[0, 0] -> 0
ị“Y4X13X2YO Retrieve the character at that index from the string.
Indexing is 1-based and modular in Jelly, so 1ị retrieves the
first character, -1ị the penultimate, and 0ị the last.
Ruby, 35 bytes
->x,y{%w[OY X14 X23][x<=>0][y<=>0]}
Leveraging the "spaceship" (<=>
) operator.
x <=> 0
will return
0
ifx == 0
1
ifx > 0
-1
ifx < 0
Hence,
if
x == 0
, we return'OY'[y<=>0]
. This isO
ify == 0
(string indexing at0
)Y
ify != 0
(this is true because both1
and-1
will result inY
when indexing on this string, as-1
refers to the last character in the string, which also happens to be the one at index 1)
if
x > 0
, we return'X14'[y<=>0]
. This isX
ify == 0
,1
ify > 0
, and4
ify < 0
(see explanation above).if
x < 0
, we return'X23'[y<=>0]
.
JavaScript, 44 bytes
(x,y)=>x?y?x>0?y>0?1:4:y>0?2:3:'X':y?'Y':'O'
f=(x,y)=>x?
y?
x>0?
y>0?1
:4
:y>0?2:3
:'X'
:y?'Y':'O'
document.body.innerHTML = '<pre>' +
'f(1,-2) -> ' + f(1,-2) + '<br>' +
'f(30,56) -> ' + f(30,56) + '<br>' +
'f(-2,1) -> ' + f(-2,1) + '<br>' +
'f(-89,-729) -> ' + f(-89,-729) + '<br>' +
'f(-89,0) -> ' + f(-89,0) + '<br>' +
'f(0,400) -> ' + f(0,400) + '<br>' +
'f(0,0) -> ' + f(0,0) + '<br>' +
'f(0,1) -> ' + f(0,1) + '<br>' +
'f(0,-1) -> ' + f(0,-1) + '<br>' +
'f(1,0) -> ' + f(1,0) + '<br>' +
'f(-1,0) -> ' + f(-1,0) + '<br>' +
'f(1,1) -> ' + f(1,1) + '<br>' +
'f(1,-1) -> ' + f(1,-1) + '<br>' +
'f(-1,1) -> ' + f(-1,1) + '<br>' +
'f(-1,-1) -> ' + f(-1,-1) + '<br>' +
'</pre>';