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!
Similar Kata:
Stats:
Created | Jan 17, 2021 |
Published | Jan 17, 2021 |
Warriors Trained | 109 |
Total Skips | 49 |
Total Code Submissions | 78 |
Total Times Completed | 27 |
C# Completions | 27 |
Total Stars | 8 |
% of votes with a positive feedback rating | 82% of 19 |
Total "Very Satisfied" Votes | 14 |
Total "Somewhat Satisfied" Votes | 3 |
Total "Not Satisfied" Votes | 2 |
Total Rank Assessments | 16 |
Average Assessed Rank | 6 kyu |
Highest Assessed Rank | 4 kyu |
Lowest Assessed Rank | 7 kyu |