Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Determinant by vvm70
def checkio(data):
if len(data) == 1:
return data[0][0]
elif len(data) == 2:
return data[0][0] * data[1][1] - data[0][1] * data[1][0]
else:
return sum((-1)**i * x * checkio([d[:i] + d[i+1:] for d in data[1:]]) for i, x in enumerate(data[0]))
#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'
Sept. 6, 2020