There are many ways to approach this, but I would start by fining one of the corners. (luckily we can't rotate the pieces).
Having found the corner (Let's say the top L (which I assume is 0 x y 0))
Now we search for all pieces that will link with either x or y (let's say x (0 v, w, x))....
For each of these pieces, we repeat the problem and since there are a limited number of pieces accross this row, the answer should fall out reasonably simply.
You can then try in another direction along an edge....
Once you have completed the border, you try to find the corner pieces INSIDE your new frame (a little harder, but with some thought you could generalise the staright edged algorithm) And work around again......
It might help to represent the pieces in a Graph where each node has 4 Arcs (one or two of which are NULL for edge pieces). You can also verify the datas validity, since you know how many pieces there are, and how many should be edges/corners.
