Last active
December 25, 2015 17:19
-
-
Save mildsunrise/7012020 to your computer and use it in GitHub Desktop.
Matrixes. Determinants. Coffeescript.
Yeah, that's pretty much it.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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