A cheap and simply way of doing this is to convert your matrix M to an upper
triagular form U using Gauss elimination. The product of the elements on the
diagonal of U equals the determinant of M. If you have to use row pivoting,
multiply that product by -1 every time you swapped two rows.