Advertisement
GalinaKG

Untitled

Oct 19th, 2022
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.83 KB | None | 0 0
  1. from collections import deque
  2.  
  3.  
  4. def move(direction_, position_):
  5.     if direction_ == 'up':
  6.         if position_[0] > 0:
  7.             position_[0] -= 1
  8.         else:
  9.             position_[0] = 5
  10.     elif direction_ == 'down':
  11.         if position_[0] < 5:
  12.             position_[0] += 1
  13.         else:
  14.             position_[0] = 0
  15.     elif direction_ == 'left':
  16.         if position_[1] > 0:
  17.             position_[1] -= 1
  18.         else:
  19.             position_[1] = 5
  20.     elif direction_ == 'right':
  21.         if position_[1] < 5:
  22.             position_[1] += 1
  23.         else:
  24.             position_[1] = 0
  25.     return position_
  26.  
  27.  
  28. matrix = []
  29. for _ in range(6):
  30.     matrix.append(input().split())
  31.  
  32. movement = deque(input().split(", "))
  33. position = []
  34.  
  35. water = 0
  36. metal = 0
  37. concrete = 0
  38.  
  39. for row, j in enumerate(matrix):
  40.     for col, el in enumerate(j):
  41.         if el == "E":
  42.             position.append(row)
  43.             position.append(col)
  44.  
  45. while movement:
  46.     current_command = movement.popleft()
  47.     position = move(current_command, position)
  48.  
  49.     if matrix[position[0]][position[1]] == "W":
  50.         water += 1
  51.         print(f"Water deposit found at ({position[0]}, {position[1]})")
  52.     elif matrix[position[0]][position[1]] == "M":
  53.         metal += 1
  54.         print(f"Metal deposit found at ({position[0]}, {position[1]})")
  55.     elif matrix[position[0]][position[1]] == "C":
  56.         concrete += 1
  57.         print(f"Concrete deposit found at ({position[0]}, {position[1]})")
  58.     elif matrix[position[0]][position[1]] == "R":
  59.         print(f"Rover got broken at ({position[0]}, {position[1]})")
  60.         break
  61.     elif matrix[position[0]][position[1]] == "-":
  62.         continue
  63.  
  64. if water != 0 and metal != 0 and concrete != 0:
  65.     print("Area suitable to start the colony.")
  66. else:
  67.     print("Area not suitable to start the colony.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement