Skip to content

Instantly share code, notes, and snippets.

@lancegatlin
Forked from ghidalgo3/submatrix
Last active August 29, 2015 14:06
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 lancegatlin/3269d3955d92fd324790 to your computer and use it in GitHub Desktop.
Save lancegatlin/3269d3955d92fd324790 to your computer and use it in GitHub Desktop.
asdf
// note: more efficient way to store matrix is a class that uses internal Buffer[Double] of size row * columns
//submatrix determination for calculating determinants of matrices
def submatrix[A](i : Int, j : Int, matrix : Array[Array[A]]) = {
//returns a new array of size n-1 with the ith index removed
def remove[A](index : Int, arr: Seq[A]): Seq[A] = {
// Note: removing the ith index from a sequence is considered highly inefficient and to be avoided whenever possible
arr.take(index) ++ arr.drop(index+1)
}
// remove row first
remove(i, matrix).map { case row => remove(j, row) }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment