Skip to content

Instantly share code, notes, and snippets.

@jamiees2
Last active December 17, 2015 00:38
Show Gist options
  • Save jamiees2/5522011 to your computer and use it in GitHub Desktop.
Save jamiees2/5522011 to your computer and use it in GitHub Desktop.
#!/bin/python
# Head ends here
def nextMove(n,y,x,grid):
princessX, princessY = findInArray('p',n,grid)
if princessY > y:
return "DOWN"
elif y > princessY:
return "UP"
if x > princessX:
return "LEFT"
elif princessX > x:
return "RIGHT"
def findInArray(s, n, arr):
for i in xrange(len(arr)):
for j in xrange(n):
if arr[i][j] == s:
return (j,i)
# Tail starts here
n = input()
x,y = [int(i) for i in raw_input().strip().split()]
grid = []
for i in xrange(0, n):
grid.append(raw_input())
print nextMove(n,x,y,grid)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment