If I add the rows and columns, I can identify which row and column
is wrong, but I can not make my program identify the position
exact.
A: yes, logic is really adding each row and column, if the sum is greater than two (2) you will know the position of the row, column with more values or where it has more 1's than it should , you should move to the position where the sum is less than two (2) this tells you exactly where is missing number 1, following its example the logic would be as follows:
For this array:
1 1 0 0
1 0 1 1
0 0 1 1
0 0 1 0
Let's start by adding all the lines first!
Add the first line of the Matrix:
1 1 0 0 ==> soma == 2 (OK)
Add the second line of the Matrix:
1 0 1 1 ==> soma == 3 (segunda linha da matriz com problema tem número a mais) > 2
Third Matrix row:
0 0 1 1 ==> soma == 2 (OK)
Fourth Matrix row:
0 0 1 0 ==> soma == 1 (quarta linha da matriz com problema tem número a menos) <2
Time to add columns:
First column:
1
1 ==> soma == 2 (OK)
0
0
Second column:
1
0 ==> soma == 1 (problema) < 2
0
0
Third column:
0
1 ==> soma == 3 (problema) > 2
1
1
Fourth column:
0
1 ==> soma == 2 (OK)
1
0
Now notice which line and column has a sum greater than two (> 2), it's going to be exactly the second line and the third column position
(2,3)
you have just found the positions with wrong values where you have more 1's than you should Now, to find which position to move to, note which position is less than two (< 2) you will notice that it will be the fourth line and second column
(4,2)
, there is a logical way to get to result!