So I did this a weird way. I noticed that there were two patterns in the way the array forms.
The first is how the top rows pattern has the difference between each term increasing from 1 -> h where h is the height and l is the length. So I construct the top row based on that pattern
For a matrix of dim(3,4) giving a max RoC = 3
We will see the top row of the form
1, (1+1), (2+2), (4+3) = 1, 2, 4, 7
Suppose instead that the dim(3,9) giving a max RoC = 3
we will instead see a top row of
`1, (1+1), (2+2), (4+3), (7+3), (10+3), (13+3), (16+3), (19+3) = 1, 2, 4, 7, 10, 13, 16, 19, 22
The second pattern is how the rows change from one another. If we consider the matrix:
1 2 4 7 11
3 5 8 12 16
6 9 13 17 20
10 14 18 21 23
15 19 22 24 25
and subtract each row from the row below (ignoring the extra row) we get
2 3 4 5 5
3 4 5 5 4
4 5 5 4 3
5 5 4 3 2
Upon seeing this matrix we can notice this matrix is the sequence 2 3 4 5 5 4 3 2
where by each row is 5 terms of this pattern shifted by 1 for each row. See below for visual.
|2 3 4 5 5| 4 3 2
2 |3 4 5 5 4| 3 2
2 3 |4 5 5 4 3| 2
2 3 4 |5 5 4 3 2|
So to get the final matrix we take our first row we created and output that row added with the 5 needed terms of this pattern.
This pattern will always have the characteristics of beginning 2-> max value
and ending max value -> 2
where the max value = min(h+1, l)
and the number of times that the max value will appear is appearances of max = h + l -2*c -2
where c = min(h+1, l) - 2
So in whole my method of creating new rows looks like
1 2 3 7 11 + |2 3 4 5 5|4 3 2 = 3 5 8 12 16
3 5 8 12 16 + 2|3 4 5 5 4|3 4 2 = 6 9 13 17 20
6 9 13 17 20 + 2 3|4 5 5 4 3|4 2 = 10 14 18 21 23
10 14 18 21 23 + 2 3 4|5 5 4 3 2| = 15 19 22 24 25
Relevant code below. It didn't end up being short but I still like the method.
o,r=len,range
def m(l,h):
a,t=[1+sum(([0]+[x for x in r(1,h)]+[h]*(l-h))[:x+1]) for x in r(l)],min(l,h+1);s,c=[x for x in r(2,t)],[a[:]]
for i in r(h-1):
for j in r(o(a)):
a[j]+=(s+[t]*(l+h-2*(t-2)-2)+s[::-1])[0+i:l+i][j]
c+=[a[:]]
for l in c:print(l)
Try it online!