-
Notifications
You must be signed in to change notification settings - Fork 38
/
bot-saves-princess-2.py
44 lines (37 loc) · 1.18 KB
/
bot-saves-princess-2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# Complete the function nextMove which takes in 4 parameters - an
# integer N, integers r and c indicating the row & column position
# of the bot and the character array grid - and outputs the next
# move the bot makes to rescue the princess.
# Link: https://www.hackerrank.com/challenges/saveprincess2
# Developer: Murillo Grubler
def nextMove(n,r,c,grid):
pos_col_m = c
pos_row_m = r
pos_col_p = pos_row_p = 0
for i in range(n):
line = len(grid[i])
for j in range(line):
if grid[i][j] == 'p':
pos_row_p = i
pos_col_p = j
# Verify the positions of the bot with the princess
if pos_row_m < pos_row_p:
pos_row_m = pos_row_m + 1
return 'DOWN'
elif pos_row_m > pos_row_p:
pos_row_m = pos_row_m - 1
return 'UP'
if pos_col_m < pos_col_p:
pos_col_m = pos_col_m + 1
return 'RIGHT'
elif pos_col_m > pos_col_p:
pos_col_m = pos_col_m - 1
return 'LEFT'
# Set the data
n = int(input())
r,c = [int(i) for i in input().strip().split()]
grid = []
for i in range(0, n):
grid.append(input())
# print the first move here
print(nextMove(n,r,c,grid))