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], 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:
1if the point is in quadrant I
2if the point is in quadrant II
3if the point is in quadrant III
4if the point is in quadrant IV
Xif the point is on the x-axis (lowercase
xis not allowed)
Yif the point is on the y-axis (lowercase
yis not allowed)
Oif 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.
(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