human
I found an interesting problem on https://www.codewars.com/kata/5ef2bc554a7606002a366006:
# 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),
          ...

I tried it in Python, but could not do it. Can you solve it?
assistant
#Here is Python code to find in what order you have to rearrange them so that the "picture" of the puzzle is complete.

def puzzle_solver(li, width, height):
    
    # save pieces of puzzle for later use
    id_number = {i[:2]: i[2] for i in li}
    li, puzzle = list(id_number.keys()), [[() for _ in range(width)] for _ in range(height)] 
    left, right, top, bottom, rest = [], [], [], [], []
    
    # set fixed corners and store sub grid to their correct place
    for grid in li:
        nones, nn = sum(i.count(None) for i in grid), (None, None)
        if nones == 3:
            x, y = [(-1, -1), (-1, 0), (0, -1), (0, 0)][next(i for i, j in enumerate(sum(grid, ())) if j is not None)]
            puzzle[x][y] = grid
        elif nones == 2:
            use = bottom if grid[1] == nn else top if grid[0] == nn else left if (grid[0][0], grid[1][0]) == nn else right
            use.append(grid)
        else:
            rest.append(grid)
    
    # function to set all sidelines
    def set_row(line, start, i, j, o, p, till):
        lookup = {k[o][p]: k for k in line}
        decide = lambda x: {(1, 1, 1, 0): (0, x), (0, 1, 0, 0): (-1, x), (1, 1, 0, 1): (x, 0)}.get((i, j, o, p), (x, -1))
    
        for k in range(1, till - 1):
            x, y = decide(k)
            puzzle[x][y] = lookup[start[i][j]]
            start = puzzle[x][y]
    
    # set all side lines
    for line, start, i, j, o, p, till in [(top, puzzle[0][0], 1, 1, 1, 0, width),
                                          (bottom, puzzle[-1][0], 0, 1, 0, 0, width),
                                          (left, puzzle[0][0], 1, 1, 0, 1, height),
                                          (right, puzzle[0][-1], 1, 0, 0, 0, height)]:
        set_row(line, start, i, j, o, p, till)
    
    #now, all easy set rest of puzzle
    prev = puzzle[0]
    lookup = {k[0]: k for k in rest}
    for k in range(1, height - 1):
        for l in range(1, width - 1):
            puzzle[k][l] = lookup[prev[l][1]]
        prev = puzzle[k]
  
    return [tuple([id_number[j] for j in i]) for i in puzzle]