# Jushbox

Jushbox is a puzzle that consists of a box containing nine stacks of pieces, arranged in a 3×3 grid. Each stack is supported underneath by a spring, very similar to coin dispensers. Each stack can hold up six pieces. The top piece of any non-empty stack can slide to the top of any adjacent stack, provided that adjacent stack does not already hold 6 pieces.
At the start, every stack has three pieces. They come in 3 colours (yellow, red, and blue), and the three columns of stacks each have a different colour. You can set yourself various objectives, such as changing the order of the coloured columns, or rearranging the pieces so that the rows are different colours instead of the columns, or making the layers different colours. This is generally not very difficult, so you may try to minimise the number of moves you need for these tasks. For each stack, only the colour of the top piece is visible, so the puzzle apparently trains your memory.

## The number of positions:

There is no simple formula for calculating the number of positions of this puzzle generally. Suppose the 27 pieces were all of the same colour. We need to find out how many ways there are to distribute 27 pieces into 9 stacks which each contain any number between 0 and 6 pieces inclusive. This can be calculated recursively. Let N(p,s) be the number of ways we can distribute p pieces into s stacks with at most 6 in any stack. The following equation then holds:

N(p,s+1) = N(p,s)+N(p-1,s)+N(p-2,s)+N(p-3,s)+N(p-4,s)+N(p-5,s)+N(p-6,s)

This counts the number of ways we to make s+1 stacks by counting all the positions that are possible before we added the 0 to 6 pieces that form the last stack. Using the trivial boundary conditions that N(0,0)=1 and N(p,0)=0 for non-zero values of p we can then find the value of N(27,9) by building the following table:

Stacks pcs 0 1 2 3 4 5 6 7 1 1 1 1 1 1 1 1 1 1 0 1 2 3 4 5 6 7 8 9 0 1 3 6 10 15 21 28 36 45 0 1 4 10 20 35 56 84 120 165 0 1 5 15 35 70 126 210 330 495 0 1 6 21 56 126 252 462 792 1,287 0 1 7 28 84 210 462 924 1,716 3,003 0 0 6 33 116 325 786 1,709 3,424 6,426 0 0 5 36 149 470 1,251 2,954 6,371 12,789 0 0 4 37 180 640 1,876 4,809 11,152 23,905 0 0 3 36 206 826 2,667 7,420 18,488 42,273 0 0 2 33 224 1,015 3,612 10,906 29,184 71,127 0 0 1 28 231 1,190 4,676 15,330 44,052 114,387 0 0 0 21 224 1,330 5,796 20,664 63,792 176,463 0 0 0 15 206 1,420 6,891 26,769 88,852 261,891 0 0 0 10 180 1,451 7,872 33,390 119,288 374,808 0 0 0 6 149 1,420 8,652 40,166 154,645 518,301 0 0 0 3 116 1,330 9,156 46,655 193,880 693,693 0 0 0 1 84 1,190 9,331 52,374 235,348 899,857 0 0 0 0 56 1,015 9,156 56,854 276,872 1,132,677 0 0 0 0 35 826 8,652 59,710 315,918 1,384,803 0 0 0 0 20 640 7,872 60,691 349,840 1,645,791 0 0 0 0 10 470 6,891 59,710 376,160 1,902,663 0 0 0 0 4 325 5,796 56,854 392,848 2,140,866 0 0 0 0 1 210 4,676 52,374 398,567 2,345,553 0 0 0 0 0 126 3,612 46,655 392,848 2,503,053 0 0 0 0 0 70 2,667 40,166 376,160 2,602,341 0 0 0 0 0 35 1,876 33,390 349,840 2,636,263

Each number in the table is the sum of the number directly to its left and the six numbers above that. So there turn out to be 2,636,263 configurations for the 27 pieces in the box, ignoring colours.

There are 27 pieces, 9 of each colour, so for each of the stack configurations there are 27!/9!3 possible arrangements of the colours. This gives a total of 2,636,263 · 27!/9!3 = 600,734,296,146,484,500 positions.

## Solutions:

This puzzle is easy to solve. You merely have to solve the bottom layer of a stack first, and only then the middle layer and finally top layer. This is done by emptying the stack, and then putting the pieces in to the empty stack in the correct order. Any solved stacks can still be used as repositories for spare pieces.

The number of positions of the puzzle as a whole is too large to calculate optimal solutions for, but it is easy to do so for three stacks that form a row. This gives some fairly short solutions for some of the transformations between nice positions. Some of these are shown below.

You can swap two adjacent stacks in 12 moves. This is very straightforward: Move all three middle pieces of a row to the right, move all three left pieces to the middle, and then the first three pieces from the right all the way to the left. This swaps the left two stacks of a row.
You can do this once in each row to swap left two adjacent columns in 36 moves. Swapping two adjacent stacks cannot be done in fewer than 12 moves if you only do moves within one row. It may be that using moves between rows can reduce the number of moves to fewer than 36, but I don't believe that to be the case.

Cyclically permuting all three columns
Simply use the method above to swap the left two columns, and then repeat it in mirror image to swap the right two columns.
Again, if you only allow moves within each row, then the 72 moves cannot be reduced. This time it is definitely possible to shorten the move sequence by using moves between rows, as follows:

1. Move one piece from the middle stack to the adjacent row.
2. Move the remaining two middle pieces to the left stack.
3. Move the three pieces in the right stack to the middle.
4. Move two pieces from the left stack back to the middle.
5. Move the three pieces from the left stack one by one over to the right stack.
6. Move two pieces from the middle stack to the left.
7. Finally, move the piece that was removed in step a back into this row and into the left stack.

This uses a total of 18 moves instead of 24, giving a total of 54 moves to permute the three columns. I do not know if this can be improved further.

Swapping the two outer (non-adjacent) columns
If you only use moves within one row, then it takes 22 moves to swap the two outer stacks, so 66 moves to swap the two outer columns. Here are the 22 moves.

1. Move one piece from the right to the middle.
2. Move one piece from the left over to the right.
3. Move one piece from the middle to the right.
4. Move two pieces from the left to the middle.
5. Move one piece from the right over to the left.
6. Move two pieces from the middle to the left.
7. Move two pieces from the right to the middle.
8. Move three pieces from the left over to the right, one by one.
9. Move two pieces from the middle to the left.

Again however, you can do this more easily and in fewer moves by temporarily putting one piece in another row.

1. Move one piece from the middle stack to the adjacent row.
2. Move three pieces from the right to the middle.
3. Move three pieces from the left over to the right, one by one.
4. Move three pieces from the middle to the left.
5. Finally, move the piece that was removed in step a back into this row in the middle stack.

This uses a total of 14 moves instead of 22, giving a total of 42 moves to swap the outer columns. I do not know if this can be improved further.

Changing three columns into three layers
If you only use moves within one row, then it takes 20 moves to rearrange the 9 pieces into three layers, giving 60 moves to make layers in the whole box. Here are the 20 moves:

1. Move three pieces from the middle to the right.
2. Move one piece from the left over to the right.
3. Move one piece from the left to the middle.
4. Move two pieces from the right to the middle.
5. Move one piece from the left to the middle.
6. Move four pieces from the right over to the left, one by one.
7. Move two pieces from the middle to the right.
8. Move one piece from the left over to the right.
9. Move one piece from the left to the middle.

Again however, you can do this more easily and in fewer moves by temporarily putting one piece in another row.

1. Move one piece from the right stack to the adjacent row.
2. Move three pieces from the middle to the right.
3. Move one piece from the left to the middle.
4. Move two pieces from the right to the middle.
5. Move one piece from the left to the middle.
6. Move three pieces from the right over to the left, one by one.
7. Move two pieces from the middle to the right.
8. Move one piece from the left to the middle.
9. Finally, move the piece that was removed in step a back into this row in the right stack.

This uses a total of 18 moves instead of 20, giving a total of 54 moves to change columns to layers. I do not know if this can be improved further.