Related: Let's design a digit mosaic, Print/Output the L-phabet. Sandbox post here
Given 2 inputs C = columns and rows, S = starting point
output a matrix as follow:
Input 4, 3
1 2 3 0
2 2 3 0
3 3 3 0
0 0 0 0
Explanation
Given C = 4, S = 3
1) Create a C x C
matrix filled with 0
4 columns
4 _____|____
| |
r --0 0 0 0
o | 0 0 0 0
w | 0 0 0 0
s --0 0 0 0
2) Fill with S
values within row and column S
, then subtract 1 from S
and repeat until S = 0
. This case S = 3
Column 3
S = 3 |
v
0 0 3 0
0 0 3 0
Row 3-->3 3 3 0
0 0 0 0
Column 2
S = 2 |
v
0 2 3 0
Row 2-->2 2 3 0
3 3 3 0
0 0 0 0
Column 1
S=1 |
v
Row 1-->1 2 3 0
2 2 3 0
3 3 3 0
0 0 0 0
Final Result
1 2 3 0
2 2 3 0
3 3 3 0
0 0 0 0
Rules
- Assume
C >= S >= 0
- The output can be a matrix, list of lists, array (1-dimensional or 2-dimensional) etc.
- You can take inputs via any default I/O format
- Your program, function, etc... may be 1-indexing or 0-indexing. Please specify which one is.
Note Explanation is 1-indexing
Winning criteria code-golf