Skip to content

Instantly share code, notes, and snippets.

@jamiees2
Created May 5, 2013 19:24
Show Gist options
  • Save jamiees2/5521882 to your computer and use it in GitHub Desktop.
Save jamiees2/5521882 to your computer and use it in GitHub Desktop.
#!/bin/python
# Head ends here
def displayPathtoPrincess(n,grid):
#Find where you are, and where the princess is
princessX, princessY = findInArray('p',n,grid)
princeX, princeY = findInArray('m',n,grid)
if princessY > princeY:
print '\n'.join(["DOWN"] * (princessY-princeY))
elif princeY > princessY:
print '\n'.join(["UP"] * (princeY - princessY))
if princeX > princessX:
print '\n'.join(["LEFT"] * (princeX - princessX))
elif princessX > princeX:
print '\n'.join(["RIGHT"] * (princessX - princeX))
def findInArray(s, n, arr):
for i in xrange(len(arr)):
for j in xrange(n):
if arr[i][j] == s:
return (j,i)
#print all the moves here
# Tail starts here
m = input()
grid = []
for i in xrange(0, m):
grid.append(raw_input().strip())
displayPathtoPrincess(m,grid)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment