Solution (source code)

= Solution

Make $F^n$ an $F[X]$-module by $Xv=Av$. It is finitely generated and torsion, so the structure theorem gives cyclic summands $F[X]/(d_i)$ with $d_1\mid\cdots\mid d_k$. In the power basis of each summand, multiplication by $X$ has the <companion matrix> of $d_i$. Their block diagonal sum is the \b[rational canonical form], unique because the invariant factors are unique.