Beta

Sarrus Fake Determinant

Description:

Rule of Sarrus is a mnemonic device for computing the determinant of a 3x3 matrix named after the French mathematician Pierre Frédéric Sarrus. In this Kata we will compute fake determinants of matrixes of various dimensions (except dimension 2 & 3 it will be fake determinants - just numbers computed by Rulo of Sarrus).

How does it work?

Write out the first (n-1) rows of the matrix to the bottom of the nth row, giving 2n-1 rows in a row. Then add the products of the diagonals going from left to right and subtract the products of the diagonals going from right to left (see description below).

Let us have a matrix M of dimension n = 3.

| 1 2 3 |
| 4 5 6 |
| 7 8 9 |

According the rule of Sarrus we just copy frist (n-1) = 2 rows to bottow and then we need to create n positive diagonals and n negative diagonals, where n is dimension of matrix - in this case 3.

| 1 2 3 |
| 4 5 6 |
| 7 8 9 |
| 1 2 3 |
| 4 5 6 |

First_positive = 1 * 5 * 9 = 45 --- First_negative = 3 * 5 * 7 = 105
Second_positive = 4 * 8 * 3 = 96 --- Second_negative = 6 * 8 * 1 = 48
Third_positive = 7 * 2 * 6 = 84 --- Third_negative = 9 * 2 * 4 = 72

After that just multiply all negative diagonal products by -1 and make total sum of all products.

result = 45 + 96 + 84 -105 -48 -72 = 0.

You will be given only valid inputs of minimal dimension of 1.

Happy coding!

Mathematics
Fundamentals

Stats:

CreatedJan 17, 2021
PublishedJan 17, 2021
Warriors Trained109
Total Skips49
Total Code Submissions78
Total Times Completed27
C# Completions27
Total Stars8
% of votes with a positive feedback rating82% of 19
Total "Very Satisfied" Votes14
Total "Somewhat Satisfied" Votes3
Total "Not Satisfied" Votes2
Total Rank Assessments16
Average Assessed Rank
6 kyu
Highest Assessed Rank
4 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • bouraccino Avatar
  • hobovsky Avatar
Ad