Suppose you have a description of good places (ones) and bad places (zeros). You want to know your distance from a bad place (in the sense of your location in the array/vector). For example:
tfs = [0 0 0 1 1 1 1 1 0 0 0 1 1 1 0 0 0];
For this scenario, we want to have:
distancesFromHoles = [0 0 0 1 2 3 2 1 0 0 0 1 2 1 0 0 0];
Lets assume that outside the sequence there are zeros. For example:
tfs = [1 1 1 0 0 1 1 0 1 1 1 1 1 1 1]; distancesFromHoles = [1 2 1 0 0 1 1 0 1 2 3 4 3 2 1];
Solution Stats
Problem Comments
1 Comment
Solution Comments
Show comments
Loading...
Problem Recent Solvers59
Suggested Problems
-
It dseon't mettar waht oedrr the lrettes in a wrod are.
2161 Solvers
-
Get the area codes from a list of phone numbers
1076 Solvers
-
Is my wife right? Now with even more wrong husband
1348 Solvers
-
Back to basics 22 - Rotate a matrix
939 Solvers
-
Generate a vector like 1,2,2,3,3,3,4,4,4,4
14224 Solvers
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
Additional test cases have been added.