[Python] How to solve for unknowns in a 5x5 matrix in python

Discussão em 'Python' iniciado por Stack, Abril 9, 2025.

  1. Stack

    Stack Membro Participativo

    Here is a 5x5 matrix, with all cells unknown, it looks something like this:

    A1+B1+C1+D1+E1| 1
    A2+B2+C2+D2+E2| 0
    A3+B3+C3+D3+E3| 1
    A4+B4+C4+D4+E4| 3
    A5+B5+C5+D5+E5| 2
    _______________
    2 1 2 1 1


    So, the summation of rows can be seen on the right, and the summation of columns can be seen on the bottom. The solution can only be 0 or 1, and as an example here is the solution to the specific one I have typed out above:

    0+0+1+0+0| 1
    0+0+0+0+0| 0
    1+0+0+0+0| 1
    1+1+0+0+1| 3
    0+0+1+1+0| 2
    ____________
    2 1 2 1 1


    As you can see, summing the rows and columns gives the results on the right and bottom. My question: How would you go about entering the original matrix with unknowns and having python iterate each cell with 0 or 1 until the puzzle is complete?

    Continue reading...

Compartilhe esta Página