Solution (source code)

= Solution

For $\sigma\in S_n$, let $P_\sigma$ be its permutation <matrix> and define the <sign of a permutation> by
$$
\operatorname{sgn}(\sigma)=\det P_\sigma\in\{\pm1\}.
$$
Since $P_{\sigma\tau}=P_\sigma P_\tau$,
$$
\operatorname{sgn}(\sigma\tau)
=\operatorname{sgn}(\sigma)\operatorname{sgn}(\tau),
$$
so this is a homomorphism. A transposition interchanges two columns of the identity <matrix> and therefore has <determinant> $-1$. If $\sigma$ is expressed as a product of $r$ transpositions, then $\operatorname{sgn}(\sigma)=(-1)^r$; because the <determinant> depends only on $\sigma$, the parity of $r$ is independent of the chosen expression.