Note that there are some explanatory texts on larger screens.

plurals
  1. POCheck for pattern recursively
    text
    copied!<p>*Note i refer to thing as a matrix but it is not, it is just a collection of 1's and zeros</p> <p>Suppose you have a matrix that is always square (n x n). Is it possible to determine if there exists a single column/row/diagonal such that each item is a 1.</p> <p>Take the matrix below for instance (True):</p> <p>1 0 0<br /> 1 1 0<br /> 0 0 1<br /></p> <p>Another example (True):</p> <p>1 1 1 <br /> 0 0 0 <br /> 0 1 0 <br /></p> <p>And finally one without a solution (False):</p> <p>0 1 1<br /> 1 0 0<br /> 0 0 0<br /></p> <p>Notice how there is a diagonal filled with 1's. The rule is there is either there is a solution or there is no solution. There can be any number of 1's or zeros within the matrix. All i really need to do is, if you have (n x n) then there should be a row/column/diagonal with n elements the same.</p> <p>If this is not possible with recursions, please let me know what is the best and most efficient method. Thanks a lot, i have been stuck on this for hours so any help is appreciated (if you could post samples that would be great).</p> <p><strong>EDIT</strong><br /> This is one solution that i came up with but it gets really complex after a while.</p> <p>Take the first example i gave and string all the rows together so you get:</p> <p>1 0 0, 1 1 0, 0 0 1 <br /> Then add zeros between the rows to get:<br /> 1 0 0 0, 1 1 0 0, 0 0 1 0<br /></p> <p>Now if you look closely, you will see that the distances between the 1's that form a solution are equal. I dont know how this can be implemented though.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload