Cody

Problem 42319. How close to a hole

Created by igor tubis in Community

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

76.32% Correct | 23.68% Incorrect
Last solution submitted on Feb 11, 2019

Problem Comments

Solution Comments

Recent Solvers24

Suggested Problems