Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def moving(row, col, direction):
- if direction == "up":
- return row - 1, col
- if direction == "down":
- return row + 1, col
- if direction == "right":
- return row, col + 1
- if direction == "left":
- return row, col - 1
- SIZE = 6
- matrix = []
- rover_row = 0
- rover_col = 0
- for row in range(SIZE):
- inner_list = input().split()
- for col in range(SIZE):
- if inner_list[col] == 'E':
- rover_row = row
- rover_col = col
- matrix.append(inner_list)
- matrix[rover_row][rover_col] = '-'
- deposits = 0
- counter = 0
- flag = False
- while not flag:
- data = input()
- data_split = data.split(', ')
- for command in data_split:
- counter += 1
- next_row, next_col = moving(rover_row, rover_col, command)
- if next_col == -1:
- next_col = SIZE - 1
- if next_col > SIZE - 1:
- next_col = 0
- if next_row == -1:
- next_row = SIZE - 1
- if next_row > SIZE - 1:
- next_row = 0
- if matrix[next_row][next_col] == 'W':
- deposits += 1
- print(f'Water deposit found at {(next_row, next_col)}')
- rover_row, rover_col = next_row, next_col
- if len(data_split) == counter:
- flag = True
- break
- elif matrix[next_row][next_col] == '-':
- rover_row, rover_col = next_row, next_col
- if len(data_split) == counter:
- flag = True
- break
- elif matrix[next_row][next_col] == 'C':
- deposits += 1
- print(f'Concrete deposit found at {(next_row, next_col)}')
- rover_row, rover_col = next_row, next_col
- if len(data_split) == counter:
- flag = True
- break
- elif matrix[next_row][next_col] == 'M':
- deposits += 1
- print(f'Metal deposit found at {(next_row, next_col)}')
- rover_row, rover_col = next_row, next_col
- if len(data_split) == counter:
- flag = True
- break
- elif matrix[next_row][next_col] == 'R':
- print(f'Rover got broken at {(next_row, next_col)}')
- rover_row, rover_col = next_row, next_col
- flag = True
- break
- if deposits >= 3:
- print(f'Area suitable to start the colony.')
- else:
- print(f'Area not suitable to start the colony.')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement