Problem 42319. How close to a hole
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
goc3
on 3 Mar 2018
Additional test cases have been added.
Solution Comments
Show commentsProblem Recent Solvers48
Suggested Problems
-
2101 Solvers
-
How to find the position of an element in a vector without using the find function
2751 Solvers
-
Project Euler: Problem 9, Pythagorean numbers
1301 Solvers
-
249 Solvers
-
Find out sum and carry of Binary adder
1542 Solvers
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!