• + 0 comments

    matrix is only N=5, might as well bruteforce recurse

    A = [
      [3,0,0,-2,4],
      [0,2,0,0,0],
      [0,-1,0,5,-3],
      [-4,0,1,0,6],
      [0,-1,0,3,2]
    ]
    def det(A):
      N = len(A)
      if N == 1: return A[0][0]
      return sum(
        (-1)**i * v * det([[v for j,v in enumerate(ls) if j != i] for ls in A[1:]])
        for i,v in enumerate(A[0])
        if v
      )
    
    print(det(A))