# Overview
The goal here is to solve a puzzle (the "pieces of paper" kind of puzzle). You will receive different pieces of that puzzle as input, and you will have to find in what order you have to rearrange them so that the "picture" of the puzzle is complete.
## Puzzle pieces
All the pieces of the puzzle will be represented in the following way:
* 4 numbers, grouped in 2 tuples, which are representing the "picture" on the piece. Every piece has a 2x2 size.
* 1 id number. All id numbers are unique in a puzzle, but their value may be random.
* Note that all numbers will be non-negative integers (except for outer border "picture" numbers in C#)
For example, 
    ((1, 2), (3, 4), 1) 
     Puzzle piece id ^  
is equivalent the the following square piece of puzzle, having the id number `1`:
    +---+
    |1 2|
    |3 4|
    +---+
If the piece is on a border or is a corner, some numbers will be replaced with `None` (`-1` in C#):
```python
((None, None), (1, 2), 10)       -->   upper border
((9, None), (None, None), 11)   -->   bottom right corner
```
Note that you cannot flip or rotate the pieces (_would you like to change the picture!?_)
## Solving the puzzle
* You'll get an array of pieces as well as the size of the puzzle (width and height).  
* Two pieces can be assembled if they share the same pattern on the border where they are in contact (see example below).
* Puzzle pieces being unique, you'll never encounter two different pieces that could be assembled with the same third one. So to say: borders are unique.
* Once you found the proper arrangment for all the pieces, return the solved puzzle as a list of tuples (height * width) of the id number of the piece at its correct position. (For C#, return the solved puzzle as a 2-dimensional array of integers.)
## Example:
Inputs:
```python
width, height = 3,3
pieces = [ ((None, 5), (None, None), 3), 
           ((17, None), (None, None), 9),
           ((None, 4), (None, 5), 8),
           ((4, 11), (5, 17), 5),
           ((11, None), (17, None), 2),   
           ((None, None), (None, 4), 7),
           ((5, 17), (None, None), 1), 
           ((None, None), (11, None), 4),
           ((None, None), (4, 11), 6) ]`
```
In this case, the expected output would be:
```python
expected = [(7, 6, 4), (8, 5, 2), (3, 1, 9)]
```
... the solved puzzle looking like this:
```python
         Puzzle Solved:                     Related id numbers:
 -----------------------------                  7    6    4
|None None|None None|None None|                 
|None   4 | 4    11 | 11  None|                 8    5    2
|-----------------------------|
|None   4 | 4    11 | 11  None|                 3    1    9
|None   5 | 5    17 | 17  None|
|-----------------------------| 
|None   5 | 5    17 | 17  None| 
|None None|None None|None None|
 -----------------------------
```
### Notes:
* Be careful about performances, you'll have to handle rather big puzzles.
* Width and height will be between 2 and 100 (inclusive)
* The puzzle may be rectangular too
def puzzle_solver(pieces, width, height):
    xs, ys, edge = list(range(width)), list(range(height)), ((None, None), (None, None))
    solution_grid = [[None for _ in xs] for _ in ys]
    id_to_piece = {p[2]: (p[0], p[1]) for p in pieces}
    code_to_id = {encode(p[0], p[1][0]): id for id, p in list(id_to_piece.items())}
    for y in ys:
        for x in xs:
            top_piece = id_to_piece[solution_grid[y-1][x]] if y > 0 else edge
            left_piece = id_to_piece[solution_grid[y][x-1]] if x > 0 else edge
            target_code = encode(top_piece[1], left_piece[1][1])
            target_id = code_to_id[target_code]
            solution_grid[y][x] = target_id
    return [tuple([solution_grid[y][x] for x in xs]) for y in ys]

def encode(top, left_bottom):
    return f"{top},{left_bottom}"
        

def puzzle_solver(pieces, width, height):
    xs, ys, edge = list(range(width)), list(range(height)), ((None, None), (None, None))
    solution_grid = [[None for _ in xs] for _ in ys]
    id_to_piece = {p[2]: (p[0], p[1]) for p in pieces}
    code_to_id = {encode(p[0], p[1][0]): id for id, p in list(id_to_piece.items())}
    for y in ys:
        for x in xs:
            top_piece = id_to_piece[solution_grid[y-1][x]] if y > 0 else edge
            left_piece = id_to_piece[solution_grid[y][x-1]] if x > 0 else edge
            target_code = encode(top_piece[1], left_piece[1][1])
            target_id = code_to_id[target_code]
            solution_grid[y][x] = target_id
    return [tuple([solution_grid[y][x] for x in xs]) for y in ys]

def encode(top, left_bottom):
    return f"{top},{left_bottom}"
        
