Problem 2409. Find the Connecting Path

Here is a matrix x

 x = [7 6 8 5 7 2 4 5 1 3 0 0 0
      7 7 7 7 7 0 0 0 0 0 0 0 0
      0 0 0 5 5 5 5 5 0 0 0 0 0
      0 0 0 1 1 1 1 1 1 0 0 0 0
      0 0 0 0 0 2 2 2 2 2 2 2 0
      0 6 6 6 6 6 0 0 0 0 0 0 0
      0 3 3 3 3 3 3 3 3 3 0 0 0
      0 0 0 0 0 0 0 0 0 2 2 2 0
      0 0 0 0 0 0 4 4 4 4 4 4 4
      0 0 8 8 8 8 8 0 0 0 0 0 0
      0 0 4 4 4 4 4 4 4 4 4 4 4
      0 3 4 1 7 6 8 0 0 2 9 0 0]

If n = 7 then the output matrix y should be

 y = [1 0 0 0 1 0 0 0 0 0 0 0 0
      1 1 1 1 1 0 0 0 0 0 0 0 0
      0 0 0 0 1 0 0 0 0 0 0 0 0
      0 0 0 0 1 0 0 0 0 0 0 0 0
      0 0 0 0 1 0 0 0 0 0 0 0 0
      0 0 0 0 1 0 0 0 0 0 0 0 0
      0 0 0 0 1 0 0 0 0 0 0 0 0
      0 0 0 0 1 0 0 0 0 0 0 0 0
      0 0 0 0 1 0 0 0 0 0 0 0 0
      0 0 0 0 1 0 0 0 0 0 0 0 0
      0 0 0 0 1 0 0 0 0 0 0 0 0
      0 0 0 0 1 0 0 0 0 0 0 0 0] 

All the places of n = 7 will become 1 and horizontally they are connected by a path given by 1's which is represented in the output y.

If n = 9 then y(12,11) = 1 and others are 0's.

Output should display path as per given n.

Solution Stats

11.38% Correct | 88.62% Incorrect
Last Solution submitted on Jul 22, 2023

Problem Comments

Solution Comments

Show comments

Problem Recent Solvers14

Suggested Problems

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!