Advertisement
Ethangx8

zz

Jan 4th, 2020
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. def findDirtySpots(board):
  2. return [(x.index('d'), i) for i, x in enumerate(board) if 'd' in x]
  3. def closest_Spot(x, y, spots):
  4. spot_dist = [(i, j, abs(i - x) + abs(j - y)) for (i,j) in spots]
  5. return (min(spot_dist, key = lambda t: t[2]))[0:2]
  6. def next_move(posr, posc, board):
  7. dirtySpots = findDirtySpots(board)
  8. c_x, c_y = closest_Spot(posc, posr, dirtySpots)
  9. if c_x == posc and c_y == posr:
  10. print("CLEAN")
  11. elif c_x == posc:
  12. print("UP" if c_y < posr else "DOWN")
  13. else:
  14. print("LEFT" if c_x < posc else "RIGHT")
  15. # Tail starts here
  16.  
  17. if __name__ == "__main__":
  18. pos = [int(i) for i in input().strip().split()]
  19. board = [[j for j in input().strip()] for i in range(5)]
  20. next_move(pos[0], pos[1], board)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement