Background
A Jordan matrix is a block-diagonal matrix where each block on the diagonal has the structure of
$$ \begin{bmatrix} \lambda & 1 & 0 & \cdots & 0 \\ 0 & \lambda & 1 & \cdots & 0 \\ \vdots & \vdots & \vdots & \ddots & \vdots \\ 0 & 0 & 0 & \lambda & 1 \\ 0 & 0 & 0 & 0 & \lambda \end{bmatrix} $$
where all values of \$\lambda\$ are identical inside each block. (A block diagonal matrix is one that can be divided into blocks, so that the blocks on the main diagonal are square and those out of the main diagonal are all zeros. See examples below.)
The following are some examples of a Jordan matrix:
$$ J_1=\left[\begin{array}{c|c|cc} 2 & 0 & 0 & 0 \\ \hline 0 & 0 & 0 & 0 \\ \hline 0 & 0 & 2 & 1 \\ 0 & 0 & 0 & 2 \end{array}\right]\\ J_2=\left[\begin{array}{ccc|cc|cc|ccc} 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ \hline 0 & 0 & 0 & 3 & 1 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 3 & 0 & 0 & 0 & 0 & 0 \\ \hline 0 & 0 & 0 & 0 & 0 & 3 & 1 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 3 & 0 & 0 & 0 \\ \hline 0 & 0 & 0 & 0 & 0 & 0 & 0 & 7 & 1 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 7 & 1 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 7 \end{array}\right] $$
The following are more examples of Jordan matrices:
[[0]] // 1x1 matrix is always Jordan
[[0, 0],
[0, 0]] // all-zero matrix is also always Jordan
[[3, 0, 0],
[0, 2, 0],
[0, 0, 2]] // diagonal matrix is also Jordan, even if it has duplicates
[[3, 0, 0],
[0, 2, 1], // the one between the two 2s is optional
[0, 0, 2]] // (if it is a zero, the two are in separate blocks)
[[99, 1, 0, 0],
[ 0, 99, 1, 0],
[ 0, 0, 99, 0],
[ 0, 0, 0, 1]] // the matrix may contain numbers >= 10
[[1, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 3, 1, 0], // same diagonal entries may appear separately
[0, 0, 0, 3, 0],
[0, 0, 0, 0, 1]]
The following are not Jordan:
[[0, 0, 0],
[0, 0, 0],
[1, 0, 0]] // has a one where it should be zero
[[2, 0, 0],
[1, 2, 0],
[0, 0, 1]] // 1 is at the wrong side of the diagonal
[[1, 1, 0],
[0, 2, 0], // the numbers on the left of and below the
[0, 0, 2]] // non-diagonal 1 are not equal
[[99, 99, 0, 0],
[ 0, 99, 99, 0],
[ 0, 0, 99, 0],
[ 0, 0, 0, 1]] // the matrix may contain numbers >= 10
[[1, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 3, 2, 0], // all numbers right above the main diagonal
[0, 0, 0, 3, 0], // should be either 0 or 1
[0, 0, 0, 0, 1]]
Challenge
Given a square matrix filled with non-negative integers, determine if it is a Jordan matrix.
Input format is flexible. For output, you can choose to
- output truthy/falsy using your language's convention (swapping is allowed), or
- use two distinct, fixed values to represent true (affirmative) or false (negative) respectively.
Standard code-golf rules apply. The shortest code in bytes wins.