Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Determinant by tokiojapan55
from itertools import permutations
from functools import reduce
from operator import mul
def sign(path):
result, path, length = 1, list(path), len(path)
while any(i != path[i] for i in range(length)):
for i in range(length):
if i != path[i]:
path[path.index(i)], path[i] = path[i], i
result *= -1
break
return result
def checkio(data):
result, length = 0, len(data)
for path in permutations(range(length)):
result += sign(path) * reduce(mul, [data[n][path[n]] for n in range(length)], 1)
return result
Jan. 23, 2024
Comments: