-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBotClean.py
32 lines (31 loc) · 917 Bytes
/
BotClean.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
# problem from https://www.hackerrank.com/challenges/botclean
#!/usr/bin/python
# Head ends here
def next_move(posr, posc, board):
out = []
for x in range(5):
for y in range(5):
if board[x][y] == 'd':
out.append([x, y])
index = 0
for k in range(len(out)):
if abs(out[k][0]- posr) + abs(out[k][1] - posc) < abs(out[index][0] - posr) + abs(out[index][1] - posc):
index = k
x = out[index][0]
y = out[index][1]
if x == posr and y == posc:
print("CLEAN")
elif x > posr:
print("DOWN")
elif x < posr:
print("UP")
else:
if y > posc:
print("RIGHT")
else:
print("LEFT")
# Tail starts here
if __name__ == "__main__":
pos = [int(i) for i in input().strip().split()]
board = [[j for j in input().strip()] for i in range(5)]
next_move(pos[0], pos[1], board)