Python
1
Вклад в тег
def determinant(matrix: list[list[int]]) -> int:
det = 0
match ln := len(matrix):
case 1:
return matrix[0][0]
case 2:
return matrix[0][0] * matrix[1][1] - matrix[0][1] * matrix[1][0]
case _:
for k in range(ln):
det += matrix[0][k] * (-1) ** k * determinant([matrix[i][:k] + matrix[i][k+1:] for i in range(1,ln)])
return det
a = [[1, 2, 9],
[4, 5 ,6],
[7, 8, 9]]
print(determinant(a))