title: counting 2*2 squares in n*n binary matrix
body: <p>I've got an n*n binary matrix (only 1 and 0), how can I go about counting 2*2 squares (squares are made by 1)</p>
  
  <p>for example <code>A=[[1,1],[1,1]]</code> is considered to make one 2*2 square. or</p>
  
  <pre><code>A = [[1, 1, 0, 1],
       [1, 1, 1, 1],
       [1, 1, 1, 0],
       [0, 1, 1, 1]]
  </code></pre>
  
  <p>is considered to make four 2*2 squares.
  here's my code for this , but I just don't know why it doesn't work.</p>
  
  <pre><code>A = [[1, 1, 0, 1] , [1, 1, 1, 1], [1, 1, 1, 0], [0, 1, 1, 1]]
  result=[]
  for x in range(len(A)-1):
      for y in range(len(A)-1):
          if A[x][y]==1:
              if A[x+1][y]==1:
                  if A[x][y+1]==1 or A[x][y-1]==1 and A[x+1][y] or A[x+1][y-1]==1:
                      result.append(1)
              if A[x-1][y]==1:
                  if A[x][y+1]==1 or A[x][y-1]==1 and A[x-1][y] or A[x-1][y-1]==1:
                      result.append(1)        
  print(len(result))        
  </code></pre>
  
  <p>`</p>