Matrix in "slash" order
Jelly, 6 5 bytes
pSÞỤs
Try it online!
How it works
pSÞỤs Main link. Left argument: n. Right argument: k
p Take the Cartesian product of [1, ..., n] and [1, ..., k], yielding
[[1, 1], [1, 2], ..., [n, k-1], [n, k]].
SÞ Sort the pairs by their sums.
Note that index sums are constant on antidiagonals.
Ụ Grade up, sorting the indices of the sorted array of pairs by their values.
s Split the result into chunks of length k.
Python 3, 91 bytes
def f(n,k):M=[(t//k+t%k,t)for t in range(n*k)];return zip(*k*[map([M,*sorted(M)].index,M)])
Try it online!
R, 101 60 54 bytes
function(M,N)matrix(rank(outer(1:M,1:N,"+"),,"l"),M,N)
Try it online!
Thanks to @nwellnhof for the suggestion of rank
Ports Dennis' Jelly answer.
Old answer, 101 bytes:
function(M,N)matrix(unsplit(lapply(split(1:(M*N),unlist(split(x,x))),rev),x<-outer(1:M,1:N,"+")),M,N)
Try it online!
split
is doing most of the work here; possibly there's a golfier algorithm but this definitely works.
Explanation:
function(M,N){
x <- outer(1:M,1:N,"+") # create matrix with distinct indices for the antidiagonals
idx <- split(x,x) # split into factor groups
items <- split(1:(M*N),unlist(idx)) # now split 1:(M*N) into factor groups using the groupings from idx
items <- lapply(items,rev) # except that the factor groups are
# $`2`:1, $`3`:2,3, (etc.) but we need
# $`2`:1, $`3`:3,2, so we reverse each sublist
matrix(unsplit(items,x),M,N) # now unsplit to rearrange the vector to the right order
# and construct a matrix, returning the value
}
Try it online! -- you can use wrap a print
around any of the right-hand sides of the assignments <-
to see the intermediate results without changing the final outcome, as print
returns its input.