Question: Function Name: olympicTorch Inputs: ( char ) MxN character array representing a map ( char ) 1xP character vector representing a path to take Outputs:
Function Name: olympicTorch
Inputs:
( char ) MxN character array representing a map
( char ) 1xP character vector representing a path to take
Outputs:
1. (logical ) Whether the given instructions lead you to your destination
Background:
It's 1984: the world is changing, and so are you. You decide to better yourself and train to be an Olympic torch relay runner. The night before the big day, however, you stay up too late working with this hot new software tool and you oversleep your alarm. Scrambling out your door, disoriented and half-awake, you can't remember who you are or where you're supposed to be. Fortunately, you manage to grab your map, but the directions are torn off! A bystander manages to decipher your nonsensical gargling and gives you a set of directions, but you can't be sure whether to trust them; after all, you're not even sure you heard them correctly...
Function Description:
Write a function called olympicTorch() that will determine whether a given path brings you to the destination on the given map.
Example:
Here is an example of a map that might be used as the first input:
####### #.. *# #.. ..# # ..# # ....# #0....# #######
The map will be surrounded by a border, represented with hash characters ( '#') . The single starting point (which can be anywhere on the map) is represented by the zero character ( '0') , and the single destination is represented as an asterisk character ( '*') . Areas that are not part of the path are filled in with period characters ( '.') .
Here is an example of a path:
'uduurruurlrr'
The characters in the path string represent the direction in which you should move:
'u' - go one space up,
'r' - go one space right,
'd' - go one space down,
'l' - go one space left.
Start at the '0' character. If the example path is followed, the destination is reached at the end of the path. Since no period or hash characters were crossed, the example path is a valid path.
If the path is valid, output a logical true , and if the path is not valid, output a logical false .
Notes:
A path will be valid if and only if it does not cross over any period or hash characters and ends up on the destination (the asterisk).
A path could, at some point, cross over the ending point but ultimately end up somewhere else (in which case it would not be valid).
The directions may lead outside of the map.
Hints:
You can use the second output of find() to determine the starting location.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
