22
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
So for the purposes of this challenge, X and Y axis are in no quadrant? – Rɪᴋᴇʀ – 2016-01-29T22:02:56.233
@RikerW Right. Otherwise the point (0, 9) could be said to be quadrant I or II. – Calvin's Hobbies – 2016-01-29T22:05:08.827
Is a complex number (or a string representation of it, like
"30+56i"
) a valid input format? – Level River St – 2016-01-29T23:21:05.787@steveverrill Yes – Calvin's Hobbies – 2016-01-29T23:50:34.877
Can the input be in the form of a complex number? (e.g.
1+2j
) – Digital Trauma – 2016-01-30T19:47:19.363