← Back to challenges

Calculate Determinant of a 2x2 Matrix

PythonHardmatharrays

Instructions

Create a function to calculate the determinant of a 2 * 2 matrix. The determinant of the following matrix is: ad - bc:

[[a, b], [c, d]]

Examples

calc_determinant([
  [1, 2],
  [3, 4]
]) ➞ -2

calc_determinant([
  [5, 3],
  [3, 1]
]) ➞ -4

calc_determinant([
  [1, 1],
  [1, 1]
]) ➞ 0

Notes

Matrix will be in 2 * 2 form only.

python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: Rotate for Max Number