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

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 03:20, owoeli
Which of these is a benefit of social networking? oa. hiding your true identity from friendsob. avoiding talking to people in personoc. spending time with friends instead of studyingod. connecting with new people
Answers: 2
image
Computers and Technology, 22.06.2019 11:10, lberman2005p77lfi
The total cost of textbooks for the term was collected from 36 students. create a histogram for this data. $140 $160 $160 $165 $180 $220 $235 $240 $250 $260 $280 $285 $285 $285 $290 $300 $300 $305 $310 $310 $315 $315 $320 $320 $330 $340 $345 $350 $355 $360 $360 $380 $395 $420 $460 $460
Answers: 2
image
Computers and Technology, 23.06.2019 19:30, wilkinsonei4069
Anul 2017 tocmai s-a încheiat, suntem trişti deoarece era număr prim, însă avem şi o veste bună, anul 2018 este produs de două numere prime, 2 şi 1009. dorel, un adevărat colecţionar de numere prime, şi-a pus întrebarea: “câte numere dintr-un interval [a, b] se pot scrie ca produs de două numere prime? “.
Answers: 1
image
Computers and Technology, 24.06.2019 08:10, anthonysutton82
Where are american poets found in the dewey decimal system
Answers: 1
You know the right answer?
Python problem

You are a Roboticist working on an algorithm to let a new Roomba cleanin...

Questions in other subjects:

Konu
Spanish, 20.04.2021 20:30