Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
cycle and itemgetter solution in Clear category for Determinant by tokyoamado
from itertools import cycle
from operator import itemgetter
def checkio(data):
d = len(data)
if d == 1:
return data[0][0]
elif d == 2:
return data[0][0] * data[1][1] - data[0][1] * data[1][0]
else:
return sum(map(
lambda x, y, z: x * y * z,
cycle((1, -1)),
data[0],
(checkio(itemgetter(*p)(list(zip(*data[1:]))))
for p in [[x for x in range(d) if x != y] for y in range(d)])
))
April 12, 2019
Comments: