Here's a puzzle. We have an $N \times N$ table. Inside each cell we write two numbers, $A_{ij}$ and $B_{ij}$, where $i,j$ denote row and column index. All numbers $A$ and $B$ are integers, $A,B \in [1, N]$. The constraints are as follows
- For each row $i$, all numbers $A_{ij}$ are different
- For each row $i$, all numbers $B_{ij}$ are different
- For each column $j$, all numbers $A_{ij}$ are different
- For each column $j$, all numbers $B_{ij}$ are different
- There are no two cells, for which the pair $(A,B)$ would be the same
Example solution for $N=3$
$$ \begin{pmatrix} 1,1 & 2,2 & 3,3 \\ 2,3 & 3,1 & 1,2 \\ 3,2 & 1,3 & 2,1 \end{pmatrix} $$
Question: Determine for which $N$ there exists a solution. For those $N$ for which the solution exists, propose an algorithm to find 1 viable solution.