Computers and Technology

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)

answer
Answers: 1

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 11:30, stodd9503
Awell-diversified portfolio needs about 20-25 stocks from different categories is this true or false?
Answers: 2
image
Computers and Technology, 24.06.2019 06:30, chloeholt123
For which utilities, if any, does the landlord pay?
Answers: 2
image
Computers and Technology, 24.06.2019 11:20, brittanybyers122
Print "censored" if userinput contains the word "darn", else print userinput. end with newline. ex: if userinput is "that darn cat.", then output is: censoredex: if userinput is "dang, that was scary! ", then output is: dang, that was scary! note: if the submitted code has an out-of-range access, the system will stop running the code after a few seconds, and report "program end never reached." the system doesn't print the test case that caused the reported message.#include #include using namespace std; int main() {string userinput; getline(cin, userinput); int ispresent = userinput. find("darn"); if (ispresent > 0){cout < < "censored" < < endl; /* your solution goes here */return 0; }
Answers: 3
image
Computers and Technology, 24.06.2019 13:00, giulissaf
Append and make table queries are called queries. select complex simple action i think action
Answers: 1
Do you know the correct answer?
Python problem

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

Questions in other subjects:

Konu
Mathematics, 01.01.2022 06:50