Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Determinant by fcborel
def minor(A,i):
N = len(A)
B = A[1:]
tab = []
for k in range(N-1):
tab.append(B[k][:i] + B[k][i+1:])
return (tab)
def checkio(A):
if len(A) == 2:
return (A[0][0]*A[1][1] - A[0][1]*A[1][0])
else:
return (sum( ((-1)**(k))*A[0][k]*checkio(minor(A,k)) for k in range(len(A))))
if __name__ == '__main__':
assert checkio([[4,3], [6,3]]) == -6, 'First'
assert checkio([[1, 3, 2],
[1, 1, 4],
[2, 2, 1]]) == 14, 'Second'
May 25, 2013