Problem 60251. Instructions Following
Complete the function follow(s) which, for a given string (containing only the letters 'f', 'b', 'l', 'r'), calculates the final position according to the following rule:
- The letter 'f' indicates to move forward by (0,1),
- The letter 'b' indicates to move backward by (0,-1),
- The letter 'l' indicates to move left by (-1,0),
- The letter 'r' indicates to move right by (1,0).
Example: consider the initial position at point (0,0). If your list of instructions is 'fflff', then you should move forward twice, take a step to the left, then move forward again twice, and finally you will be at (-1, 4):
Other examples:
- follow('ffrff') returns (1,4)
- follow('fblr') returns (0,0)
Solution Stats
Problem Comments
Solution Comments
Show commentsProblem Recent Solvers13
Suggested Problems
-
Replace NaNs with the number that appears to its left in the row.
3010 Solvers
-
How to find the position of an element in a vector without using the find function
2744 Solvers
-
Check to see if a Sudoku Puzzle is Solved
324 Solvers
-
middleAsColumn: Return all but first and last element as a column vector
611 Solvers
-
Mysterious digits operation (easy)
292 Solvers
More from this Author53
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!