subject

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)

ansver
Answers: 1

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 07:30
Events and conditions that happen within an organization that are somewhat easier to deal with when responding to change are called
Answers: 1
question
Computers and Technology, 23.06.2019 20:30
If an appliance consumes 500 w of power and is left on for 5 hours, how much energy is used over this time period? a. 2.5 kwh b. 25 kwh c. 250 kwh d. 2500 kwh
Answers: 1
question
Computers and Technology, 24.06.2019 00:00
Which tool could be used to display only rows containing presidents who served two terms
Answers: 3
question
Computers and Technology, 24.06.2019 00:50
Which of the following is not a key player in the sale of travel products?
Answers: 2
You know the right answer?
Python problem

You are a Roboticist working on an algorithm to let a new Roomba cleanin...
Questions
question
History, 23.03.2020 03:02
question
Mathematics, 23.03.2020 03:02
question
Chemistry, 23.03.2020 03:02
question
Mathematics, 23.03.2020 03:03
question
Mathematics, 23.03.2020 03:03
Questions on the website: 13722360