Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Youre trapped in the bottom-left corner of a w h escape room, and need to cross to the door in the upper-right corner to escape.

Youre trapped in the bottom-left corner of a w h escape room, and need to cross to the door in the upper-right corner to escape. But, the door will only unlock if you follow the correct path. Fortunately, you have directions for the path to follow across the grid cells on the floor, but the directions are incomplete. The partial path is represented as a string composed of the following characters {U, D, L, R, ?}, where each character represents a direction to take along the grid: U = up, D = down, L = left, R = right. The question marks represent unknown steps that you must figure out. You know that the path may not cross the same grid cell twice.

Write a function CompletePath(s, w, h) that takes in three arguments: a string s representing the partial path, and two integers w and h specifying the room size. Your

3

function should return a string that represents the completed path, with all question marks filled in with the correct directions to take you from the bottom-left corner of the grid to the upper-right corner. If no path is possible, your function should return None. Your function should properly error-check all arguments.

For example: in a 5 5 room, if s = "URD?RUU?UR" then your function should return the completed path to exit the room, "URDRRUUUUR".

Here are a few sample test cases:

 CompletePath("?RDRR?UUUR", 5, 5) = "URDRRUUUUR" CompletePath("UURDD?UUR?R?", 6, 4) = "UURDDRUURURR" 

Complete this function in the iPython notebook.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Fred R. McFadden, Jeffrey Slater, Mary B. Prescott

5th Edition

0805360549, 978-0805360547

Students also viewed these Databases questions

Question

8. Describe how cultural spaces are formed.

Answered: 1 week ago