Python problem
You are a Roboticist working on an algorithm to let a new Roomba cleanin...
Computers and Technology, 19.05.2020 14:57 rhyanebean6443
Python problem
You are a Roboticist working on an algorithm to let a new Roomba cleaning robot know which places are dirty in it's environment.
The first number is the number of lists making up the environment. The Roomba's environment is simplified as a string of inputs, with 'c' indicating somewhere clean, and 'd' indicating somewhere dirty and 'r' indicating the current position of the roomba as follows:
2
rdcdc
dcccd
The Roomba can take the following actions:
right
left
down
clean
The directions are moves the Roomba can take in the specified direction, and clean is the action the Roomba takes to clean a dirt spot.
Create a function called ToClean(environ) that takes a nested list of strings as inputs and returns a list of strings where the list is the order of actions the robot needs to take to clean the environment.
You only need to have the robot clean the dirty spaces in the order they appear in the environ from left to right up to down.
For example, if the input is:
2
rdcdc
dcccd
This can be represented as a coordinate grid using a list of lists. For example,
[[0,0] , [0,1], [0,2], [0,3], [0,4],
[1,0] , [1,1], [1,2], [1,3], [1,4]]
Then the output would be:
['right', 'clean', 'right', 'right', 'clean', 'left', 'left', 'left', 'down', 'clean', 'right', 'right', 'right', 'right', 'clean']
Hints
The Roomba always starts in the upper left corner (position [0,0])
2.Get the locations of the dirty spaces first, then loop through those to decide the Roomba’s actions For example, the dirty coordinates above are:
[[0,1], [0,3],
[1,0], 1,4]]
Use the location of the Roomba in relation to the dirty space locations to decide the actions For example, if the Roomba starts at [0,0]and the next coordinate in the dirty list is [0,1] you can see that [0,0] The 0 in bold is less than [0,1] the 1 in bold, which indicates the robot must go right.
Similarly, if the Roomba is at [0,3] and the next dirty space is [1,0] since 3 > 0 the Roomba must go left 3 times, and since 0 < 1 the Roomba must go down 1 time.
You should not modify the input lists to get the actions. Simply make variables to reference the locations in the input lists.
code provide in the problem is:
def ToClean(environ):
pass
if __name__ == '__main__':
environ = []
lst_dim = int(input())
for i in range(lst_dim):
lstinput = list(input())
environ. append(lstinput)
action_list = ToClean(environ)
print(action_list)
Answers: 1
Computers and Technology, 23.06.2019 09:30
Name the range function that would generate the following list of integers values: 0,1,2,3,4,5.
Answers: 1
Computers and Technology, 23.06.2019 21:20
In microsoft word, when you highlight existing text you want to replace, you're in a. advanced mode. b. automatic mode. c. basic mode. d. typeover mode
Answers: 1
Computers and Technology, 24.06.2019 03:30
Which explains extrinsic motivation? a)motivation in which there is a reward b)motivation that is personally satisfying c)motivation that is personally meaningful d)motivation in which the subject is interesting
Answers: 1
Computers and Technology, 24.06.2019 13:30
Consider jasper’s balance sheet. which shows how to calculate jasper’s net worth?
Answers: 1
Mathematics, 22.08.2019 18:30
Health, 22.08.2019 18:30
English, 22.08.2019 18:30
English, 22.08.2019 18:30
Physics, 22.08.2019 18:30
Social Studies, 22.08.2019 18:30
History, 22.08.2019 18:30
Mathematics, 22.08.2019 18:30