Advertisement
horozov86

martian_explorer

Jun 14th, 2023 (edited)
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.45 KB | None | 0 0
  1. def moving(row, col, direction):
  2.     if direction == "up":
  3.         return row - 1, col
  4.  
  5.     if direction == "down":
  6.         return row + 1, col
  7.  
  8.     if direction == "right":
  9.         return row, col + 1
  10.  
  11.     if direction == "left":
  12.         return row, col - 1
  13.  
  14.  
  15. SIZE = 6
  16. matrix = []
  17. rover_row = 0
  18. rover_col = 0
  19. for row in range(SIZE):
  20.     inner_list = input().split()
  21.     for col in range(SIZE):
  22.         if inner_list[col] == 'E':
  23.             rover_row = row
  24.             rover_col = col
  25.     matrix.append(inner_list)
  26.  
  27. matrix[rover_row][rover_col] = '-'
  28. deposits = 0
  29. counter = 0
  30. flag = False
  31. while not flag:
  32.  
  33.     data = input()
  34.     data_split = data.split(', ')
  35.     for command in data_split:
  36.         counter += 1
  37.         next_row, next_col = moving(rover_row, rover_col, command)
  38.         if next_col == -1:
  39.             next_col = SIZE - 1
  40.  
  41.         if next_col > SIZE - 1:
  42.             next_col = 0
  43.  
  44.         if next_row == -1:
  45.             next_row = SIZE - 1
  46.  
  47.         if next_row > SIZE - 1:
  48.             next_row = 0
  49.  
  50.         if matrix[next_row][next_col] == 'W':
  51.             deposits += 1
  52.             print(f'Water deposit found at {(next_row, next_col)}')
  53.             rover_row, rover_col = next_row, next_col
  54.             if len(data_split) == counter:
  55.                 flag = True
  56.                 break
  57.  
  58.         elif matrix[next_row][next_col] == '-':
  59.             rover_row, rover_col = next_row, next_col
  60.             if len(data_split) == counter:
  61.                 flag = True
  62.                 break
  63.  
  64.         elif matrix[next_row][next_col] == 'C':
  65.             deposits += 1
  66.             print(f'Concrete deposit found at {(next_row, next_col)}')
  67.             rover_row, rover_col = next_row, next_col
  68.             if len(data_split) == counter:
  69.                 flag = True
  70.                 break
  71.  
  72.         elif matrix[next_row][next_col] == 'M':
  73.             deposits += 1
  74.             print(f'Metal deposit found at {(next_row, next_col)}')
  75.             rover_row, rover_col = next_row, next_col
  76.             if len(data_split) == counter:
  77.                 flag = True
  78.                 break
  79.  
  80.         elif matrix[next_row][next_col] == 'R':
  81.             print(f'Rover got broken at {(next_row, next_col)}')
  82.             rover_row, rover_col = next_row, next_col
  83.             flag = True
  84.             break
  85.  
  86. if deposits >= 3:
  87.     print(f'Area suitable to start the colony.')
  88. else:
  89.     print(f'Area not suitable to start the colony.')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement