Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Determinant by old_user
# migrated from python 2.7
def determinant(matr):
"""calculate determinant for square matrix
using recursive algorithm"""
if len(matr) == 2:
return matr[0][0] * matr[1][1] - matr[0][1] * matr[1][0]
elif len(matr) == 1:
return matr[0][0]
else:
return sum([((-1)**(j)) * matr[0][j] *
determinant([matr[1+i][:j] + matr[1+i][j+1:]
for i in range(len(matr)-1)])
for j in range(len(matr))])
def checkio(data):
'determinant value'
return determinant(data)
April 28, 2011
Comments: