Skip to content

Instantly share code, notes, and snippets.

@sbsatter
Created May 24, 2018 20:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sbsatter/5f1947947c43aadeec79d603ec43650d to your computer and use it in GitHub Desktop.
Save sbsatter/5f1947947c43aadeec79d603ec43650d to your computer and use it in GitHub Desktop.
import math
def nextMove(n,r,c,grid):
princess = ()
for row in range(n):
for col in range(len(grid[row])):
if grid[row][col] == 'p':
princess = (row, col)
break
m = (r, c)
x = princess[0] - m[0]
y = princess[1] - m[1]
if x != 0:
dir = 'DOWN' if x > 0 else 'UP'
elif y != 0:
dir = 'RIGHT' if y > 0 else 'LEFT'
else :
print((x, y))
return dir
n = int(input())
r,c = [int(i) for i in input().strip().split()]
grid = []
for i in range(0, n):
grid.append(input())
print(nextMove(n,r,c,grid))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment