Skip to content

Instantly share code, notes, and snippets.

@bhalothia
Created July 7, 2020 17:44
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 bhalothia/a75052eb07edb671851deffe1ff2bfbc to your computer and use it in GitHub Desktop.
Save bhalothia/a75052eb07edb671851deffe1ff2bfbc to your computer and use it in GitHub Desktop.
# Problem statement: https://www.hackerrank.com/challenges/botcleanlarge
def next_move(posx, posy, dimx, dimy, board):
if board[posx][posy] == 'd':
print("CLEAN")
return
dirty_cells = []
min_dist = 200
min_x = None
min_y = None
for x in range(dimx):
for y in range(dimy):
if board[x][y] == 'd':
dirty_cells.append((x,y))
for x, y in dirty_cells:
if abs(posx - x) + abs(posy - y) < min_dist:
min_dist = abs(posx - x) + abs(posy - y)
min_x = x
min_y = y
if posx - min_x < 0:
print("DOWN")
elif posx - min_x > 0:
print("UP")
elif posy - min_y < 0:
print("RIGHT")
else:
print("LEFT")
if __name__ == "__main__":
pos = [int(i) for i in input().strip().split()]
dim = [int(i) for i in input().strip().split()]
board = [[j for j in input().strip()] for i in range(dim[0])]
next_move(pos[0], pos[1], dim[0], dim[1], board)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment