Created
May 5, 2013 19:24
-
-
Save jamiees2/5521882 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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