Skip to main content
7 of 7
added 125 characters in body
Dennis
  • 211.7k
  • 41
  • 380
  • 830

Jelly, 24 19 15 13 11 bytes

pS€żị"¥pỤị⁵ 

Takes number of rows, number of columns and a flat list as separate command-line arguments.

Try it online!

How it works

pS€żị"¥pỤị⁵ Main link. Argument: m (rows), n (columns), A (list, flat) p Compute the Cartesian product [1, ..., m] × [1, ..., n]. This yields the indices of the matrix M, i.e., [[1, 1], [1, 2], ..., [m, n]]. S€ Compute the sums of all index pairs. p Yield the Cartesian product. ¥ Dyadic chain. Arguments: Sums, Cartesian product. ị" For each index pair in the Cartesian product, retrieve the coordinate at the index of its sum, i.e., map [i, j] to i if i + j is odd and to j if i + j is even. ż Zip the sums with the retrieved indices. Ụ Sort [1, ..., mn] by the corresponding item in the resulting list. ị⁵ Retrieve the corresponding items from A. 
Dennis
  • 211.7k
  • 41
  • 380
  • 830