Skip to content

Instantly share code, notes, and snippets.

@popey456963
Created October 28, 2015 15:11
Show Gist options
  • Select an option

  • Save popey456963/5aee029570ab345dd29f to your computer and use it in GitHub Desktop.

Select an option

Save popey456963/5aee029570ab345dd29f to your computer and use it in GitHub Desktop.
Octant
def get_octant(x,y):
try:
if abs(x)/abs(y) == 1:
return "undefined"
except:
return "undefined"
dx, dy = x,y
octant = 0
if dy < 0:
dx, dy = -dx, -dy # rotate by 180 degrees
octant += 4
if dx < 0:
dx, dy = dy, -dx # rotate clockwise by 90 degrees
octant += 2
if dx < dy:
# no need to rotate now
octant += 1
return octant
n = int(input())
for i in range(n):
data = input().split()
print(get_octant(int(data[0]),int(data[1])))
@popey456963
Copy link
Copy Markdown
Author

50%

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment