24
disclaimer: I'm not aware of any non-bruteforce solutions
A Graeco-Latin square is, for two sets of same length \$n\$, a \$n \times n\$ arrangement of cells, each containing a unique (across the entire square) pair of a element of the first set and a element of the second set, such that all first elements and all second elements of the pairs are unique in their row and column. The most common sets used are, as one could guess, the first \$n\$ letters of the Greek and the Latin alphabets.
Here is a picture of a 4x4 Graeco-Latin square:
Graeco-Latin squares are as useful as they sound (the Wikipedia article mentions "design of experiments, tournament scheduling and constructing magic squares"). Your task is, given a positive integer \$n\$, to generate a \$n\times n\$ Graeco-Latin square.
Input
A positive integer \$n > 2\$; it is guaranteed that a \$n\times n\$ Graeco-Latin square exists (that is, \$n \ne 6\$).
Output
A Graeco-Latin square with side length n as a two-dimensional array, a array of arrays, a flattened array or outputted directly.
Notes
- You do not have to use the Greek and Latin alphabets specifically; for example, outputting pairs of positive integers is allowed as well.
- If you choose to use a alphabet that can't be extended arbitrarily, you have to (theoretically; your code doesn't have to finish before the heat death of the universe) support a maximal side length of at least 20.
This is code-golf, so the shortest code wins!
Sandbox link – my pronoun is monicareinstate – 2019-06-04T01:52:13.360
Do we have to output a single square, or is it ok to output all possible squares as a list? – Nick Kennedy – 2019-06-04T22:40:58.427