6
Task
Given is a square matrix of any dimension and any integer n.
Output all possible matrices(without duplicates) by removing columns and rows from the input matrix such that the determinant of these new matrices is n.
Rules
Output should include original if determinant of original is n.
Output should be all the chopped off matrices. In case no output matrix is possible, return 0 or None or anything similar.
The input matrix will be at least of size 2x2 and all elements will be integers.
If n=1 empty matrix must also be in the output.
Test Cases
inputs:
[[1,0,5],
[1,0,5],
[1,2,4]],2
[[1, 3, 5],
[1, 3, 5],
[1, 45, 4]],0
[[1, 22, 5, 4],
[1, 3, 5, 5],
[1, 45, 4, 6],
[3, 4, 1, 4]],5
[[1, 22, 5, 4],
[1, -32, 51, 5],
[1, 45, 9, 0],
[3, 4, -1, -6]],-54
[[1, 22, 5, 4],
[1, -32, 51, 5],
[1, 45, 9, 0],
[3, 4, -1, -6]],1
outputs:
[[[2]], [[1, 0], [1, 2]]]
[[[1, 3], [1, 3]], [[1, 5], [1, 5]], [[3, 5], [3, 5]], [[1, 3, 5], [1, 3, 5], [1, 45, 4]]]
[[[5]], [[5, 4], [5, 5]]]
[[[1, 22], [1, -32]], [[9, 0], [-1, -6]]]
[[], [[1]], [[1, 4], [1, 5]]]
The shortest code wins.
2+1 for making me think about why the determinant of the empty matrix really should be 1. – ngm – 2018-11-13T19:43:31.700