Skip to content

Instantly share code, notes, and snippets.

@RReverser
Last active December 10, 2015 21:48
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 RReverser/4498097 to your computer and use it in GitHub Desktop.
Save RReverser/4498097 to your computer and use it in GitHub Desktop.
Functional recursive solution for calculating matrix determinant
private double det(IEnumerable<IEnumerable<double>> matrix)
{
return
matrix.Any()
?
matrix
.Select((row, i) =>
(i % 2 == 0 ? +1 : -1)
* row.First()
* det(matrix.Where((curRow, curI) => curI != i).Select(curRow => curRow.Skip(1)))
)
.Sum()
: 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment