Problem 2406. possible ways through matrix
This problem is inspired from problem 2405 <https://www.mathworks.com/matlabcentral/cody/problems/2405-the-number-of-ways>.
Check that problem description first for better understanding. Input p is the number of rows and n the number of columns of matrix A. Matrix A is filled with numbers from 1 to n*p in a row-wise fashion. Example:
n=2; p=2
A = [1 2
3 4];
The objective is to move through the matrix starting from the top row (at any position) and end at bottom row (at any position). The difference with problem 2405 is that here the movement is limited. You can not jump from, say, 3rd column of 1st row to 1st column of 2nd row. If you are at j-th column of i-th row, the only valid next movements are (i+1,j-1), (i+1,j) and (i+1,j+1). That means, you can only move vertically or diagonally (in both direction). No wrap around the edges is assumed (will be in next problem). Just like the previous problem, return a matrix where each row is a possible move.
For the example given above, the possible moves are (1,3), (1,4), (2,3) and (2,4). Thus the output matrix is
[1 3
1 4
2 3
2 4]
Solution Stats
Problem Comments
-
1 Comment
Dyuman Joshi
on 6 Oct 2022
Test cases added.
Many of the submitted answers fail for n=2,p=1 case.
Solution Comments
Show commentsProblem Recent Solvers32
Suggested Problems
-
448 Solvers
-
8987 Solvers
-
347 Solvers
-
Generate binary combinations for a given number of bit(s)
92 Solvers
-
183 Solvers
More from this Author44
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!