Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Determinant by Agrigor
def checkio(data):
if len(data) == 1:
return data[0][0]
else:
result = 0
for i in range(len(data)):
minor = [[data[x][y] for y in range(len(data[0])) if y != i] for x in range(len(data)) if x != 0]
result += data[0][i] * (-1)**(i) * checkio(minor)
return result
#These "asserts" using only for self-checking and not necessary for auto-testing
if __name__ == '__main__':
assert checkio([[4, 3], [6, 3]]) == -6, 'First example'
assert checkio([[1, 3, 2],
[1, 1, 4],
[2, 2, 1]]) == 14, 'Second example'
May 15, 2016
Comments: