Determinate (Python)

From LiteratePrograms
Jump to: navigation, search
Other implementations: Haskell | Python
<<determinate.py>>=
def determinate(matrix):
    if len(matrix) == 2 and len(matrix[0]) == 2:
        return matrix[0][0] * matrix[1][1]\
             - matrix[0][1] * matrix[1][0]
    else:
        submatrices = map(lambda i: map(lambda vector: vector[1:],
            matrix[:i] + matrix[i+1:]), [i for i in range(len(matrix))])
        return sum(map(lambda submatrix: determinate(submatrix), submatrices))
Download code
hijacker
hijacker
hijacker
hijacker