# Crackerblocks: computing solutions for IQ Block game

The IQ Block game is a puzzle where the player must fit eight shapes into a square space. The challenge is to find as many ways as possible to do it.

The box says there are more than 40 solutions! So how many are there?

I wrote a solver to crack the IQ Block game. The code is available here and a detailed description is at the end of the post. The solver found 264 solutions from 33 placements. Many of these solutions were duplicates, which meant there were 48 unique solutions.

Here they are:

## How the puzzle works

There are eight blocks, each with a unique shape. They must fit into a square space which is 8 x 8 units with no gaps. Each block is 8 square units in size and the space is 64 square units.

The instructions are to fit a block in the top left corner and then fit the remaining blocks to find a solution. This tells us that the orientation of the space is important. Rotations and reflections of a solution will count as different solutions.

## How the solver works

The puzzle can be treated as an 8 x 8 image where we fill the image with pixels of eight different values. I coded a solution in IGOR Pro to solve the puzzle this way, by brute force. This approach, although slow, meant that I am certain that all combinations have been attempted. In the end, the code ran 13 times longer than it needed to, since all solutions were found after only 5.8 x 10^8 iterations.

The code makes 8 matrices one for each block. The pixels corresponding to the block are filled in and then these matrices are duplicated (and reflected and/or rotated) to find all possible unique orientations for placement. So blocks have between 2 and 8 possible orientations. Since all eight blocks must be placed for a solution, we can generate all the permutations of these orientations (131072 permutations) and then select from those in all possible combinations (40320). This is 5.28 x 10^9 ways that the blocks can be placed.

Some optimisation was required to save on computing time. One improvement I made was to check if the placement would mean that the first (or last) block, in the top left (or bottom right) of the image, would result in a trapped empty pixel. That situation would mean a solution was impossible, so the attempt can be skipped to save time. In the final run 2.5 x 10^9 attempts were made and 3 x 10^9 attempts were skipped with that change, which halved the compute time. There were many more inefficiencies in my code and it could definitely be improved to go faster!

The program had one rule for fitting the blocks in a predetermined order. This was to place the blocks sequentially in the next available space. This strategy gives pretty good coverage of the total search space, but it is incomplete. We know that it is incomplete since not all solutions were found using it, however, the strategy found enough solutions that we had four-fold saturation in the end. What does that mean?

Well, the program found 33 solutions using its search strategy. Each solution could be rotated and reflected to give 8 variations of each solution. So the program found 264 solutions. Now, many of these will not be unique, so using a distance matrix to reject identical solutions, these were whittled down to 48 solutions.

Knowing the maximum number of solutions, would allow us to optimise the code to find all solutions in the fastest way. However, we only knew there were more than 40 solutions at the start, so the code had to be open-ended to find all the solutions.

## Conclusion

The IQ Block game is a fun puzzle with 48 solutions. They are available on this page if anyone is stuck!

EDIT: 2022-01-10 T14:52:38Z The post was corrected to show 48 solutions. Previously, due to an error, the post suggested that there were 64 solutions, when in fact some of these were duplicates. Thanks to commenter John for pointing this out!

The post title comes from “Crackerblocks” by Ozric Tentacles from their Erpland LP. Plenty of songs in my library with “block” in the title, but this was the most appropriate.

## 11 thoughts on “Crackerblocks: computing solutions for IQ Block game”

1. John says:

Re: Crackerblocks: computing solutions for IQ Block game, You state there are 64 solutions, and that they are all shown on page, BUT you only show 48. solutions. That’s all I have so far been able to confirm too.

1. Hi John. In the post there are three images. The first two have 24 solutions (48 total) and the last image has 16 (64 total). You might need to click them to see the full image. I think each one is a unique solution.

2. john says:

16 of the blocks appear to be duplicated in your block diagrams, leaving just 48 unique patterns. I’ve even pasted all your 64 results into Microsoft Word, then gave each group a grid reference to help me compare them visually, to arrive at this conclusion.

3. John says:

You have me doubting now, so I’ll double check my observations.

4. John says:

Rechecked and happy with my 48 figure. Consider a couple of associated duplications on your screen, with the centre group of your 3 groups, columns left to right number them say 1 to 4, then rows, top to bottom 1 to 6. Comparing top left group, ie, 1,1, with 4th row down, ie, 3.4, they are identical. A similar situation applies to the other 15 groups that I’m querying.

1. Hi John, thank you for explaining. Yes, I agree there are duplicates. I am perplexed why those 16 duplicates are there. Obviously I didn’t check the results carefully enough, but I was sure my approach for rejecting duplicates was robust. I will take a look at the code to see if I can figure out the reason.

1. John says:

Interestingly, happypuzzle.co.uk also claim 64 unique patterns, and their solutions have the same duplicates, leaving just 48 correct; did you write their check code by any chance? I’ve been wondering about your coding, I’d not have a clue how to code each shape, but I am not familiar with IGOR Pro. Well done anyway, and it would be interesting to hear what may have caused the duplication. Does your routine include a final duplication check and reject type routine?

5. John says:

I’ve not ruled out the possibility of more than 48 solutions, perhaps even 64, now trying to work out what extras there might be, a great little puzzle!

6. john says:

If you ignore the flips and rotations, for 48 solutions, it just leaves 6 unique patterns, so perhaps that might be an approach for a computing solution to looking for any others?

1. I’m still in the process of verifying the code. I think I might have identified why the duplicates made it into the final tally but I want to make sure what the final answer is.

You are correct about the flips and rotations. As I wrote in the post, the puzzle states that you start with a piece in the top left, so flips and rotations of a solution are unique in the sense that there is a different puzzle piece in the top left corner. Once my code finds a solution, it does indeed do all the flips and rotations to find the other (related) solutions. What seems to have failed is the checking step. Well, the checking step worked for many of the duplicates, but not the 16 that remain. This is the perplexing thing… I will update the post when I figure it out.

2. I have rerun the code and it finds only 48 solutions! I haven’t been able to determine where the error came from that led me to 64 solutions with duplicates. Possibly, I ran the solver in two halves (it takes a long time to run) and then made a mistake manually assembling the final figure.

Thanks a lot for pointing this out. I will correct the post and leave a note about my error.