Answered step by step
Verified Expert Solution
Question
1 Approved Answer
2 Need help with Python code with best performance There is a cleaning robot in a room. The room is described by an array of
Need help with Python code with best performance There is a cleaning robot in a room. The room is described by an array of strings, where represents an empty floor area, an area the robot cannot enter obstacles such as walls or furniture and is the initial position of the robot. It is possible to reach all empty floor areas from the robot's initial position. Rows are numbered from to from top to bottom, and columns are numbered from to from left to right in other words, field is the upperleft corner The room is always surrounded by walls # which means that there are always walls in columns and and in rows and Your task is to generate a sequence of commands consisting of moves: up down v left and right such that the robot will clean all the required fields depending on the subtask, full room or just the borders of the room The robot cleans all the fields it visits, including the field the robot starts on The robot should never step into any obstacles, but it can enter the same field multiple times. The robot may finish at any field it does not have to return to the starting point Write a function:that, given an array room consisting of R strings, each of length C and an integer subtask representing the type of subtask the function should solve subtasks a Subtask Room shape: a simple rectangle; Starting position: the topleft corner; Area to be cleaned: the border of the room fields adjacent to the walls For example, for room ######## ## ## ######## one of the possible sequences that your function may return is: Vve A graphical representation of this example is shown in the picture below. The expected areas to be cleaned are colored in blue, and the blocked areas are in gray, marked by The robot is allowed to enter areas that are not required to be cleaned that are white in the picture Subtask changes saved Subtask Room shape: a simple rectangle; Starting position: no constraints can be any field; Area to be cleaned: the whole floor. For example, for room ######## ## ## ## ####### one of the possible sequences that your function Subtask Room shape: a rectangle divided into two smaller rectangular parts by a vertical toptobottom wall, connected by a singlefield passage; Starting position: no constraints can be any field; Subtask Room shape: a rectangle divided into two smaller rectangular parts by a vertical toptobottom wall, connected by a singlefield passage; Starting position: no constraints can be any field; Area to be cleaned: the whole floor. For example, for room ######### ## # ######## one of the possible sequences that your function may return is: Subtask Room shape: any shape. The room may also contain some additional obstacles besides the walls for example furniture; Starting position: no constraints can be any field; Area to be cleaned: the whole floor. For example, for room ########### #### # ## ############# one of the possible sequences that your function may return is: re described below returns the string representing the required sequence of commands. Constraints Assume that: each string in array room consists only of the following characters: # and ; there is exactly one starting point, marked by ; all empty fields can be reached from the starting point; and are integers within the range ; the generated sequence can not contain more than commands. Subtasks may specify additional assumptions. Subtasks: Your solution's score will depend on how many subtasks it is able to solve. Each subtask is worth an equal number of points Each subtask may differ in three categories: expected area to be cleaned; room shape; starting point of the robot. Subtask Room shape: a simple rectangle; Starting position: the topleft corner; Area to be cleaned: the border of the room fields adjacent to the walls
Need help with Python code with best performance
There is a cleaning robot in a room. The room is described by an array of strings, where represents an empty floor area, an area the robot cannot enter obstacles such as walls or furniture and is the initial position of the robot. It is possible to reach all empty floor areas from the robot's initial position. Rows are numbered from to from top to bottom, and columns are numbered from to from left to right in other words, field is the upperleft corner The room is always surrounded by walls # which means that there are always walls in columns and and in rows and
Your task is to generate a sequence of commands consisting of moves: up down v left and right such that the robot will clean all the required fields depending on the subtask, full room or just the borders of the room The robot cleans all the fields it visits, including the field the robot starts on The robot should never step into any obstacles, but it can enter the same field multiple times. The robot may finish at any field it does not have to return to the starting point
Write a function:that, given an array room consisting of R strings, each of length C and an integer subtask representing the type of subtask the function should solve subtasks a
Subtask
Room shape: a simple rectangle;
Starting position: the topleft corner;
Area to be cleaned: the border of the room fields adjacent to the walls
For example, for room ######## ## ## ######## one of the possible sequences that your function may return is: Vve
A graphical representation of this example is shown in the picture below. The expected areas to be cleaned are colored in blue, and the blocked areas are in gray, marked by The robot is allowed to enter areas that are not required to be cleaned that are white in the picture
Subtask
changes saved
Subtask
Room shape: a simple rectangle;
Starting position: no constraints can be any field;
Area to be cleaned: the whole floor.
For example, for room ######## ## ## ## ####### one of the possible sequences that your function
Subtask
Room shape: a rectangle divided into two smaller rectangular parts by a vertical toptobottom wall, connected by a singlefield passage;
Starting position: no constraints can be any field;
Subtask
Room shape: a rectangle divided into two smaller rectangular parts by a vertical toptobottom wall, connected by a singlefield passage;
Starting position: no constraints can be any field;
Area to be cleaned: the whole floor.
For example, for room ######### ## # ######## one of the possible sequences that your function may return is:
Subtask
Room shape: any shape. The room may also contain some additional obstacles besides the walls for example furniture;
Starting position: no constraints can be any field;
Area to be cleaned: the whole floor.
For example, for room ########### #### # ## ############# one of the possible sequences that your function may return is: re described below returns the string representing the required sequence of commands.
Constraints
Assume that:
each string in array room consists only of the following characters: # and ;
there is exactly one starting point, marked by ;
all empty fields can be reached from the starting point;
and are integers within the range ;
the generated sequence can not contain more than commands.
Subtasks may specify additional assumptions.
Subtasks:
Your solution's score will depend on how many subtasks it is able to solve. Each subtask is worth an equal number of points Each subtask may differ in three categories:
expected area to be cleaned;
room shape;
starting point of the robot.
Subtask
Room shape: a simple rectangle;
Starting position: the topleft corner;
Area to be cleaned: the border of the room fields adjacent to the walls
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started