Write a program or function that takes in two integers that represent the X and Y coordinates of a point on a Cartesian plane.
The input may come in any reasonable format as long as the X value comes before the Y. For example, 1 -2
, (1,-2)
, [1, -2]
, or 1\n-2
would all be fine for X = 1, Y = -2.
Print or return a single character string (followed by an optional trailing newline) that describes the location of the point in the plane:
1
if the point is in quadrant I2
if the point is in quadrant II3
if the point is in quadrant III4
if the point is in quadrant IVX
if the point is on the x-axis (lowercasex
is not allowed)Y
if the point is on the y-axis (lowercasey
is not allowed)O
if the point is on the origin (that's a capital letter "oh", not zero)
The shortest code in bytes wins. Tiebreaker goes to the higher voted answer.
Test Cases
(1,-2) -> 4
(30,56) -> 1
(-2,1) -> 2
(-89,-729) -> 3
(-89,0) -> X
(0,400) -> Y
(0,0) -> O
(0,1) -> Y
(0,-1) -> Y
(1,0) -> X
(-1,0) -> X
(1,1) -> 1
(1,-1) -> 4
(-1,1) -> 2
(-1,-1) -> 3
"30+56i"
) a valid input format? \$\endgroup\$ – Level River St Jan 29 '16 at 23:211+2j
) \$\endgroup\$ – Digital Trauma Jan 30 '16 at 19:47