Created
May 24, 2018 19:51
-
-
Save sbsatter/eeaa50d1b892135166bc70c338204b19 to your computer and use it in GitHub Desktop.
Bot Saves Princess Hackerrank AI problem: https://www.hackerrank.com/challenges/saveprincess
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
#!/usr/bin/python | |
import math | |
def displayPathtoPrincess(n,grid): | |
#print all the moves here | |
princess = () | |
for row in range(n): | |
for col in range(len(grid[row])): | |
if grid[row][col] == 'p': | |
princess = (row, col) | |
break | |
m = (n//2, n//2) | |
x = m[0] - princess[0] | |
y = m[1] - princess[1] | |
dir = 'UP\n' if x > 0 else 'DOWN\n' | |
print(dir * int(math.fabs(x)), end='') | |
dir = 'LEFT\n' if y > 0 else 'RIGHT\n' | |
print(dir * int(math.fabs(y)), end='') | |
m = int(input()) | |
grid = [] | |
for i in range(0, m): | |
grid.append(input().strip()) | |
displayPathtoPrincess(m,grid) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment