# Task
 Given a rectangular matrix containing only digits, calculate the number of different `2 × 2` squares in it.

# Example

 For
```
matrix = [[1, 2, 1],
          [2, 2, 2],
          [2, 2, 2],
          [1, 2, 3],
          [2, 2, 1]]
```
the output should be `6`.

 Here are all 6 different 2 × 2 squares:
 
 ```
 1 2
 2 2

 2 1
 2 2

 2 2
 2 2

 2 2
 1 2

 2 2
 2 3

 2 3
 2 1
 ```

# Input/Output


 - `[input]` 2D integer array `matrix`

    Constraints: 
    
    `1 ≤ matrix.length ≤ 100,`
    
    `1 ≤ matrix[i].length ≤ 100,`
    
    `0 ≤ matrix[i][j] ≤ 9.`


 - `[output]` an integer

    The number of different `2 × 2` squares in matrix.

Difficulty: introductory

Starter code:

def different_squares(matrix):
	

Solutions:
def different_squares(matrix):
    s = set()
    rows, cols = len(matrix), len(matrix[0])
    for row in range(rows - 1):
        for col in range(cols - 1):
            s.add((matrix[row][col], matrix[row][col + 1], matrix[row + 1][col], matrix[row + 1][col + 1]))
    return len(s)

def different_squares(matrix):
    squares = []
    for r in range(len(matrix)-1):
        for c in range(len(matrix[0])-1):
            squares.append((matrix[r][c],matrix[r][c+1],matrix[r+1][c],matrix[r+1][c+1]))
    return len(set(squares))
            
            
        
        
        


different_squares = lambda m: len({(m[i][j], m[i][j+1], m[i+1][j], m[i+1][j+1]) for i in range(len(m)-1) for j in range(len(m[0])-1)})

def different_squares(matrix):
    result = []
    for i in range(len(matrix) - 1):
        for j in range(len(matrix[0]) - 1):
            one = [
                matrix[i][j:j + 2],
                matrix[i + 1][j:j + 2]
            ]
            if one not in result:
                result.append(one)
    return len(result)


def different_squares(matrix):
    m, n = len(matrix), len(matrix[0])
    return len({tuple(matrix[i][j:j+2] + matrix[i+1][j:j+2]) for i in range(m-1) for j in range(n-1)})

from itertools import chain

pairwise = lambda a: list(zip(a, a[1:]))
transpose = lambda a: list(zip(*a))

def different_squares(matrix):
    if 1 in (len(matrix), len(matrix[0])):
        return 0
    all_squares = chain.from_iterable(map(pairwise, map(transpose, pairwise(matrix))))
    unique_squares = set(all_squares)
    return len(unique_squares)

def different_squares(matrix):
    squares = []
    for r in range(len(matrix)-1):
        for c in range(len(matrix[0])-1):
            squares.append((matrix[r][c], matrix[r][c+1], matrix[r+1][c], matrix[r+1][c+1]))
    unique = set(squares)
    return len(unique)


def different_squares(matrix):
    h, w = len(matrix), len(matrix[0]) if matrix else 0
    return len(set(((matrix[i][j], matrix[i][j+1]), (matrix[i+1][j], matrix[i+1][j+1]))  for i in range(h-1) for j in range(w-1)))


def different_squares(matrix):
    return len(set(tuple(tuple(row[j:j+2]) for row in matrix[i:i+2]) for i in range(len(matrix)-1) for j in range(len(matrix[0])-1)))

def different_squares(mat):
    v = set()
    for i in range(len(mat) - 1):
        for j in range(len(mat[0]) - 1):
            v.add((mat[i][j], mat[i][j + 1], mat[i + 1][j], mat[i + 1][j+1]))
    
    return len(v)