Skip to main content
added 125 characters in body
Source Link
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 (outdated)

pµS€©-*×Ṫ€®żỤị⁵pS€żị"¥pỤị⁵ Main link. Argument: nm (rows), mn (columns), A (list, flat) p  Compute P, the Cartesian product of [1, ..., n]m] and× [1, ..., m]n]. This yields µ the indices of Beginthe amatrix newM, monadic chaini.e., Argument:[[1, P 1], [1, S€2], ..., [m, n]].  S€  Compute the sums of all index pairs. © p Yield the Cartesian product.  Save the resulting list in the¥ register Dyadic chain. Arguments: Sums, Cartesian product. ị" -* For each index pair Computein (-1)**sthe forCartesian eachproduct, sumretrieve s.the coordinate ×Ṫ€ at Multiplythe withindex theof secondits coordinatessum, ofi.e., allmap pairs[i, inj] P. to i if i + j is odd and to  ®ż Zip the list in the register with thej listif ofi products+ j is even.  ż  Zip the sums with the retrieved indices.   Sort [1, ..., nm]mn] by the corresponding item in thatthe resulting list.   ị⁵  Retrieve the corresponding items from A. 

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 (outdated)

pµS€©-*×Ṫ€®żỤị⁵ Main link. Argument: n (rows), m (columns), A (list, flat) p  Compute P, the Cartesian product of [1, ..., n] and [1, ..., m]. µ Begin a new, monadic chain. Argument: P  S€ Compute the sums of all pairs. © Save the resulting list in the register. -* Compute (-1)**s for each sum s. ×Ṫ€ Multiply with the second coordinates of all pairs in P.  ®ż Zip the list in the register with the list of products. Ụ Sort [1, ..., nm] by the corresponding item in that list.   ị⁵ Retrieve the corresponding items from A. 

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. 
added 7 characters in body
Source Link
Dennis
  • 211.7k
  • 41
  • 380
  • 830

Jelly, 24 19 15 1313 11 bytes

pUS¡€U+\€UỤị⁵pS€żị"¥pỤị⁵ 

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

Try it online!Try it online!

How it works (outdated)

pµS€©-*×Ṫ€®żỤị⁵ Main link. Argument: n (rows), m (columns), A (list, flat) p Compute P, the Cartesian product of [1, ..., n] and [1, ..., m]. µ Begin a new, monadic chain. Argument: P S€ Compute the sums of all pairs. © Save the resulting list in the register. -* Compute (-1)**s for each sum s. ×Ṫ€ Multiply with the second coordinates of all pairs in P. ®ż Zip the list in the register with the list of products. Ụ Sort [1, ..., nm] by the corresponding item in that list. ị⁵ Retrieve the corresponding items from A. 

Jelly, 24 19 15 13 bytes

pUS¡€U+\€UỤị⁵ 

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

Try it online!

How it works (outdated)

pµS€©-*×Ṫ€®żỤị⁵ Main link. Argument: n (rows), m (columns), A (list, flat) p Compute P, the Cartesian product of [1, ..., n] and [1, ..., m]. µ Begin a new, monadic chain. Argument: P S€ Compute the sums of all pairs. © Save the resulting list in the register. -* Compute (-1)**s for each sum s. ×Ṫ€ Multiply with the second coordinates of all pairs in P. ®ż Zip the list in the register with the list of products. Ụ Sort [1, ..., nm] by the corresponding item in that list. ị⁵ Retrieve the corresponding items from A. 

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 (outdated)

pµS€©-*×Ṫ€®żỤị⁵ Main link. Argument: n (rows), m (columns), A (list, flat) p Compute P, the Cartesian product of [1, ..., n] and [1, ..., m]. µ Begin a new, monadic chain. Argument: P S€ Compute the sums of all pairs. © Save the resulting list in the register. -* Compute (-1)**s for each sum s. ×Ṫ€ Multiply with the second coordinates of all pairs in P. ®ż Zip the list in the register with the list of products. Ụ Sort [1, ..., nm] by the corresponding item in that list. ị⁵ Retrieve the corresponding items from A. 
added 8 characters in body
Source Link
Dennis
  • 211.7k
  • 41
  • 380
  • 830

Jelly, 24 19 1515 13 bytes

pµS€©-*×Ṫ€®żỤị⁵pUS¡€U+\€UỤị⁵ 

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

Try it online!Try it online!

How it works (outdated)

pµS€©-*×Ṫ€®żỤị⁵ Main link. Argument: n (rows), m (columns), A (list, flat) p Compute P, the Cartesian product of [1, ..., n] and [1, ..., m]. µ Begin a new, monadic chain. Argument: P S€ Compute the sums of all pairs. © Save the resulting list in the register. -* Compute (-1)**s for each sum s. ×Ṫ€ Multiply with the second coordinates of all pairs in P. ®ż Zip the list in the register with the list of products. Ụ Sort [1, ..., nm] by the corresponding item in that list. ị⁵ Retrieve the corresponding items from A. 

Jelly, 24 19 15 bytes

pµS€©-*×Ṫ€®żỤị⁵ 

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

Try it online!

How it works

pµS€©-*×Ṫ€®żỤị⁵ Main link. Argument: n (rows), m (columns), A (list, flat) p Compute P, the Cartesian product of [1, ..., n] and [1, ..., m]. µ Begin a new, monadic chain. Argument: P S€ Compute the sums of all pairs. © Save the resulting list in the register. -* Compute (-1)**s for each sum s. ×Ṫ€ Multiply with the second coordinates of all pairs in P. ®ż Zip the list in the register with the list of products. Ụ Sort [1, ..., nm] by the corresponding item in that list. ị⁵ Retrieve the corresponding items from A. 

Jelly, 24 19 15 13 bytes

pUS¡€U+\€UỤị⁵ 

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

Try it online!

How it works (outdated)

pµS€©-*×Ṫ€®żỤị⁵ Main link. Argument: n (rows), m (columns), A (list, flat) p Compute P, the Cartesian product of [1, ..., n] and [1, ..., m]. µ Begin a new, monadic chain. Argument: P S€ Compute the sums of all pairs. © Save the resulting list in the register. -* Compute (-1)**s for each sum s. ×Ṫ€ Multiply with the second coordinates of all pairs in P. ®ż Zip the list in the register with the list of products. Ụ Sort [1, ..., nm] by the corresponding item in that list. ị⁵ Retrieve the corresponding items from A. 
added 723 characters in body
Source Link
Dennis
  • 211.7k
  • 41
  • 380
  • 830
Loading
edited body
Source Link
Dennis
  • 211.7k
  • 41
  • 380
  • 830
Loading
added 91 characters in body
Source Link
Dennis
  • 211.7k
  • 41
  • 380
  • 830
Loading
Source Link
Dennis
  • 211.7k
  • 41
  • 380
  • 830
Loading