Skip to main content
Function name change
Source Link

Python 3, 153153 149 Bytes

def detd(n):
 l=len(n);r=range(0,l)
 if l==1:return n[0][0]
 else:return sum([(-1)**i*n[0][i]*det**i*n[0][i]*d([[n[a][b]for b in r if b!=i]for a in r[1:]])for i in r])

I'm new to code golf, so I wouldn't be surprised if this could be improved. It's calculated in a pretty basic way; by summing the product of each element of the first row with the determinant of its respective minor, with a sign change based on the element's position.

Edit: Realized I could shorten it by using a single character for the function name :/

Python 3, 153 Bytes

def det(n):
 l=len(n);r=range(0,l)
 if l==1:return n[0][0]
 else:return sum([(-1)**i*n[0][i]*det([[n[a][b]for b in r if b!=i]for a in r[1:]])for i in r])

I'm new to code golf, so I wouldn't be surprised if this could be improved. It's calculated in a pretty basic way; by summing the product of each element of the first row with the determinant of its respective minor, with a sign change based on the element's position.

Python 3, 153 149 Bytes

def d(n):
 l=len(n);r=range(0,l)
 if l==1:return n[0][0]
 else:return sum([(-1)**i*n[0][i]*d([[n[a][b]for b in r if b!=i]for a in r[1:]])for i in r])

I'm new to code golf, so I wouldn't be surprised if this could be improved. It's calculated in a pretty basic way; by summing the product of each element of the first row with the determinant of its respective minor, with a sign change based on the element's position.

Edit: Realized I could shorten it by using a single character for the function name :/

Source Link

Python 3, 153 Bytes

def det(n):
 l=len(n);r=range(0,l)
 if l==1:return n[0][0]
 else:return sum([(-1)**i*n[0][i]*det([[n[a][b]for b in r if b!=i]for a in r[1:]])for i in r])

I'm new to code golf, so I wouldn't be surprised if this could be improved. It's calculated in a pretty basic way; by summing the product of each element of the first row with the determinant of its respective minor, with a sign change based on the element's position.