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
Problem Comments
-
6 Comments
syntax error at y_correct. Remove spaces between '=' and '['
new test suite has been added.
yes.. and that is wrong either (dimension mismatch). Next, your question statement is also ambiguous. 4's in the second test suite can be connected in multiple ways, dont know what you are asking.
Starting from the top you should travel to bottom. Repeating no. displays vertical path and you should think about only horizontal missing places.
forget the logic. Your test suite 2 is still broken
This problem needs to have its description improved. It is not clear why some path must prefered over another like on test case #2. Why the fours must cross at the borders when the sevens didn't? Can we only add one 1 per row? and what's the priority of paths?
Solution Comments
Show commentsProblem Recent Solvers15
Suggested Problems
-
8897 Solvers
-
1167 Solvers
-
760 Solvers
-
716 Solvers
-
367 Solvers
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!