Skip to content

Instantly share code, notes, and snippets.

@ghidalgo3
Created September 18, 2014 22:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ghidalgo3/3f07af1b6a4f33162857 to your computer and use it in GitHub Desktop.
Save ghidalgo3/3f07af1b6a4f33162857 to your computer and use it in GitHub Desktop.
//submatrix determination for calculating determinants of matrices
def submatrix(i : Int, j : Int, matrix : Array[Array]) = {
//returns a new array of size n-1 with the ith index removed
def removeIndex(index : Int, arr: Array): Array = {
arr
.zipWithIndex //what you call if you need an indexed loop
.filter{ case (_,index) => index != r }
.map { case (value, _) => value }
}
removeIndex(i , matrix.map{ case row => removeIndex(j, row) } )
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment