Determinant of a square bigint matrix via cofactor expansion (n ≤ 4 here).
(m: bigint[][])
| 99 | |
| 100 | /** Determinant of a square bigint matrix via cofactor expansion (n ≤ 4 here). */ |
| 101 | function det(m: bigint[][]): bigint { |
| 102 | const n = m.length; |
| 103 | if (n === 0) return 1n; |
| 104 | if (n === 1) return m[0][0]; |
| 105 | if (n === 2) return m[0][0] * m[1][1] - m[0][1] * m[1][0]; |
| 106 | let sum = 0n; |
| 107 | for (let j = 0; j < n; j++) { |
| 108 | const minor = m.slice(1).map((row) => row.filter((_, ci) => ci !== j)); |
| 109 | const sign = j % 2 === 0 ? 1n : -1n; |
| 110 | sum += sign * m[0][j] * det(minor); |
| 111 | } |
| 112 | return sum; |
| 113 | } |
| 114 | |
| 115 | function* combinations<T>(pool: T[], k: number): Generator<T[]> { |
| 116 | if (k === 0) { |
no test coverage detected