Question: write in python: We now wish to produce a sequence of moves to clean all of the dirt the Vacuuminator can find, and then return

write in python: We now wish to produce a sequence of moves to clean all of the dirt the Vacuuminator can find, and then return the Vacuuminator to its starting position. The Vacuuminator should repeatedly scan for and clean up dirt found from its current position according to the rules in Task 3. It should continue to do so as long as it finds new dirt from its current position. We will call this a cleaning cycle.
Once the Vacuuminator is no longer able to find any new dirt, it should backtrack along its path, scanning for new dirt at each square. If it finds any new dirt in its scan it should begin a new cleaning cycle, starting with this dirt.
The Vacuuminator should continue until it has backtracked through every move it has made and found no more dirt, scanning and cleaning as it goes. Note that once the Vacuuminator has selected a patch of dirt to clean, it will not scan for any new dirt until that patch has been cleaned. Scanning for new dirt will only happen while the Vacuuminator is backtracking.
Write a function clean_path(world). This function should return a list of moves that the Vacuuminator will use to clean the world according to the rules above.
A working version of the Task 3 path_to_next(world) function is provided to help you with this task. Example example cases:
>>> clean_path([['E','D'],['E','E'],['E','X']])
['u','u','d','d']
>>> clean_path([['D','D'],['E','E'],['E','X']])
['u','u','l','r','d','d']
>>> clean_path([['E','D','E'],['X','D','D'],['E','E','E']])
['r','u','d','r','l','l']
>>> clean_path([['E','D','E'],['X','D','E'],['E','D','E']])
['r','u','d','d','u','u','d','l']
>>> clean_path([['E','D','D'],['D','E','E'],['D','E','X']])
['u','u','l','r','d','l','l','d','u','r','r','d']

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!