Skip to content

Instantly share code, notes, and snippets.

@mildsunrise
Last active December 25, 2015 17:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mildsunrise/7012020 to your computer and use it in GitHub Desktop.
Save mildsunrise/7012020 to your computer and use it in GitHub Desktop.
Matrixes. Determinants. Coffeescript. Yeah, that's pretty much it.
determinant = (M) ->
k = M.length
return 1 unless k
# copy child matrix
N = []
for y in [1...k]
N.push M[y].slice 1
# recurse
ret = 0
for x in [0...k]
d = determinant N
d = -d if x%2
ret += M[0][x]*d
for y in [1...k]
N[y-1][x] = M[y][x]
return ret
result = determinant [ [ 0, -1, +3 ]
, [ -2, +3, 0 ]
, [ -5, -3, +2 ] ]
console.log "There you have it:", result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment