Wooden Block Solver

Are you a programmer? Got any of those wooden block puzzles, that you have to form into a cube? If its too hard, then here's a program to solve it for you. Its not elegant, its not efficeint, and its certainly not user-friendly, but it came in very handy for me, and who knows, somebody else might find it useful.

To use it save the following text as "blocks.py", and then run it using the command :

python blocks.py

(You'll need to install python if you don't already have it).

Wooden Block Solver.txt

You should see output such as :


5 2 2 
5 5 2 
6 6 1 

5 2 2 
4 6 6 
4 6 1 

5 2 2 
4 2 1 
4 4 1 

This tells you were each piece has to go. For example, piece 1 is a "L" shaped piece, which is standing up in the south east corner, with the fat piece pointing north.

The code is very simple, it just brute-forces all possible combinations till it finds a solution (well actually it finds ALL solutions). On my laptop it takes less than 8 seconds to find a solution for a 3x3x3 cube with 6 pieces. So, there's no need to optimise it.

If you are using it to solve your own puzzle, then you'll need to define your own pieces. Look at the end of the source code, and hopefully it will make sense. The first number is just an identifier used when printing the solution, the array defines the position of the mini-cubes occupied by the piece when it is placed in the bottom left corner of the playing area. You aren't allowed to use -ve numbers.

You may notice that the code has two definitions for piece 5. That's because my piece #5 broke, and I wasn't sure which way round it went, so I wanted to solve both ways round. The piece5m is the mirror image of piece5, and there are many solutions with piece5m, so piece5 must be the correct one.

I'm off to find my glue gun...