Assume that $n\times n$ real matrix $A$ is in Jordan canonical form. Also, assume that $A$ has $k$ distinct positive real eigenvalues; and that for each eigenvalue it has maximum two Jordan blocks. Using similarity transformation we can shuffle the Jordan blocks of $A$. Let the final $A$ be equal to:
$$\hat{A}=\begin{bmatrix}A_1&0\\0&A_2\end{bmatrix},$$
such that single $A_i$ cannot contain two Jordan block with equal eigenvalues. This is combinatorial problem and among all the variations, I want to obtain the one such that $\det(A_1)$ is as close as possible to $\det(A_2)$.
Examples:
$$A=\begin{bmatrix}3&0&0&0\\0&2&1&0\\0&0&2&0\\0&0&0&2\end{bmatrix}\rightarrow \hat{A}=\begin{bmatrix}3&0&0&0\\0&2&0&0\\0&0&2&1\\0&0&0&2\end{bmatrix}, A_1=\begin{bmatrix}3&0\\0&2\end{bmatrix}, A_2=\begin{bmatrix}2&1\\0&2\end{bmatrix}$$
$$A=\begin{bmatrix}5&1&0&0&0&0&0\\0&5&0&0&0&0&0\\0&0&5&0&0&0&0\\0&0&0&2&1&0&0\\0&0&0&0&2&1&0\\0&0&0&0&0&2&0\\0&0&0&0&0&0&2\end{bmatrix}\rightarrow \hat{A}=\begin{bmatrix}5&1&0&0&0&0&0\\0&5&0&0&0&0&0\\0&0&2&0&0&0&0\\0&0&0&5&0&0&0\\0&0&0&0&2&1&0\\0&0&0&0&0&2&1\\0&0&0&0&0&0&2\end{bmatrix}, A_1=\begin{bmatrix}5&1&0\\0&5&0\\0&0&2\end{bmatrix}, A_2=\begin{bmatrix}5&0&0&0\\0&2&1&0\\0&0&2&1\\0&0&0&2\end{bmatrix}$$
When $A$ has just couple of eigenvalues I can do the splitting into $A_i$ by hand, but when there are many different eigenvalues computation becomes tricky. Is there a smart way this can be done, is it possible to code such combinatorial problem?