<p>This looks like the <a href="http://en.wikipedia.org/wiki/Exact_cover" rel="nofollow">Exact Cover Problem</a>. You basically want to cover all fields on the board with your given pieces. I can recommend <a href="http://en.wikipedia.org/wiki/Dancing_Links" rel="nofollow">Dancing Links</a>, published by Donald Knuth. In the <a href="http://arxiv.org/pdf/cs/0011047v1.pdf" rel="nofollow">paper</a> you find a clear example for the <a href="http://en.wikipedia.org/wiki/Pentomino" rel="nofollow">pentomino problem</a> which should give you a good idea of how it works.</p>

<p>You basically set up a system that keeps track of all possible ways to place a specific block on the board. By placing a block, you would cover a set of positions on the field. These positions can't be used to place any other blocks. All possibilities would then be erased from the problem setting before you place another block. The dancing links allows for fast backtracking and erasing of possibilities.</p>
brute forcing a brain puzzle
<p>I was given a brain puzzle from lonpos.cc as a present. I was curius of how many different solutions there were, and I quite enjoy writing algorithms and code, so I started writing an application to brute force it.</p>

<p>The puzzle looks like this : <a href="http://www.lonpos.cc/images/LONPOSdb.jpg" rel="nofollow">http://www.lonpos.cc/images/LONPOSdb.jpg</a> / <a href="http://cdn100.iofferphoto.com/img/item/191/498/944/u2t6.jpg" rel="nofollow">http://cdn100.iofferphoto.com/img/item/191/498/944/u2t6.jpg</a></p>

<p>It's a board of 20x14 "points". And all puzzle pieces can be flipped and turned. I wrote an application where each piece (and the puzzle) is presented like this:</p>

<pre><code>01010
00100
01110
01110
11111
01010
</code></pre>

<p>Now my application so far is reasonably simple.</p>

<p>It takes the list of pieces and a blank board, pops of piece #0
flips it in every direction, and for that piece tries to place it for every x and y coordinate. If it successfully places a piece it passes a copy of the new "board" with some pieces taken to a recursive function, and tries all combinations for their pieces.</p>

<p>Explained in pseudocode:</p>

<pre><code>bruteForce(Board base, List pieces) {
    for (Piece in pieces.pop, piece.pop.flip, piece.pop.flip2...) {
        int x,y = 0;
        if canplace(piece, x, y) {
            Board newBoard = base.clone();
            newBoard.placePiece(piece, x, y);
            bruteForce(newBoard, pieces);
        }
        ## increment x until x &gt; width, then y
    }
}
</code></pre>

<p>Now I'm trying to find out ways to make this quicker. Things I've thought of so far:</p>

<ol>
<li>Making it solve in parallel - Implemented, now using 4 threads.</li>
<li>Sorting the pieces, and only trying to place the pieces that will fit in the x,y space we're trying to fit. (Aka if we're on the bottom row, and we only have 4 "points" from our position to the bottom, dont try the ones that are 8 high).</li>
<li>Not duplicating the board, instead using placePiece and removePiece or something like it.</li>
<li>Checking for "invalid" boards, aka if a piece is impossible to reach (boxed in completely).</li>
</ol>

<p>Anyone have any creative ideas on how I can do this quicker? Or any way to mathematically calculate how many different combinations there are? </p>