# Ramka

Ramka is a Soviet puzzle with 9 numbered tiles arranged in 3 rows of 3 tiles. These rows lie in a frame which provides two empty spaces, one on either side of a row, each capable of holding one of the tiles. The centre section containing the tile rows can be shifted up and down so that any of the three rows lies between the spaces provided by the frame. The tiles can individually only slide sideways along a row, not vertically.

The Russian word "Ramka" means "frame". On the back of the puzzle the price is given as 80 kopeks.

If your browser supports JavaScript, then you can play Ramka by clicking the link below:

## The number of positions:

This depends on what are considered to be distinct positions. There are 11 tile locations, with 9 distinct tiles and 2 empty spaces. That would lead to 11!/2 = 19,958,400 tile positions, or 3·11!/2 = 59,875,200 if vertical shifts of the block of rows are counted as distinct.
I prefer to ignore not only the vertical shifts of the rows, but also horizontal shifts within the three locations on a row. In that case there are 13 arrangements for the empty spaces (both in the frame; one on the left of the frame and the other in any row; one on the right of the frame and the other in any row; both on the same row, or both on different rows). Combined with the 9! ways to rearrange the 9 tiles, that gives 13*9! = 4,717,440 distinct positions.

I have used a computer to calculate God's Algorithm, and the results are shown in the table below. A move is the sliding of a tile from a row into one of the frame spaces, or vice versa. Sliding the block of rows vertically or sliding tiles horizontally within a row are not counted as moves, and arrangements that differ by such changes are considered identical.

Depth# Positions
01
16
29
312
430
548
684
7126
8234
9354
10660
Depth# Positions
111,008
121,791
132,670
144,951
157,308
1612,888
1718,708
1833,006
1946,476
2079,314
21108,006
Depth# Positions
22180,488
23234,780
24369,138
25436,764
26624,868
27628,032
28734,086
29518,478
30418,966
31158,388
3273,448
Depth# Positions
3314,916
345,602
351,044
36502
37138
3884
3912
406
416
424
Total4,717,440

One of the four antipodes is the mirror image position (with the rows reading 321, 654, 987). The other three antipodes are similar to that position but with the two outer tiles of one row slid into the frame's spaces.

## Solutions:

This puzzle is slightly trickier than it looks. It can be solved however by using the following two techniques (both start with the frame locations empty):

1. Cycling two rows. This cyclically permutes the 6 pieces of two rows.
1. Shift one row to the right (one tile moves into the frame's right-hand side space).
2. Shift another row to the left (add the tile from the frame's rhs space to the row, and that row's left tile goes into the frame's lhs space).
3. Finally use the left tile to fill the space in the previous row.
 1 2 3 4 5 6 7 8 9
 1 2 3 4 5 6 7 8 9
 1 2 3 6 4 5 7 8 9
 1 2 3 6 4 5 7 8 9
 2 3 6 1 4 5 7 8 9
 2 3 6 1 4 5 7 8 9
2. Swapping two tiles. This swaps the right-most tile of row X with the right-most tile of row Y. It makes temporary use of row the other row too, which I'll call row Z.
1. Push the right-most tile of row X to the right into the frame's rhs space.
2. Push that tile left onto row Z (Row Z's left tile goes into the frame's lhs space).
3. Push the right-most tile of row Y to the right into the frame's rhs space.
4. Push that tile left onto row X.
5. Push the whole of row Z to the right (including the tile that went into the frame's lhs space) so that the tile originally from row X is now in the frame's rhs space.
6. Push that tile left onto row Y.
 1 2 3 4 5 6 7 8 9
 1 2 3 4 5 6 7 8 9
 1 2 3 6 4 5 7 8 9
 1 2 3 6 4 5 7 8 9
 2 3 6 4 5 1 7 8 9
 2 3 6 4 5 1 7 8 9
 2 3 6 1 4 5 9 7 8
 2 3 6 1 4 5 9 7 8
 1 2 3 6 4 5 9 7 8
 1 2 3 6 4 5 9 7 8
 1 2 3 4 5 9 7 8 6
 1 2 3 4 5 9 7 8 6

These two techniques are sufficient to solve any position.

Phase 1: Solve the top row

1. If the top row contains tiles 1, 2 or 3, then cycle the top row with another row in order to remedy that. It is always possible to choose the other row and the direction in such a way that the tiles 1, 2, and 3 will not end up on the top row.
2. Cycle the bottom two rows until the 1 is on the right of a row.
3. Cycle the top row and the row containing 1 so that the 1 enters the right of the top row.
4. Repeat steps b and c for tile 2 so that the 1 is now in the middle of the top row with 2 at the end.
5. Repeat steps b and c for tile 3 so that top row is solved.

Phase 2: Bring the tiles to their rows

1. Imagine that the tiles 4, 5, and 6 had a different colour from the tiles 7, 8, and 9. If the last two rows both alternate in colour (i.e. no two of the same colour are next to each other) then perform the swap sequence.
2. Cycle the bottom two rows until on each row, the left two tiles have the same colour.
3. If the bottom two rows do not yet have one colour each, then performing the swap sequence should make it so.
4. If necessary, cycle the bottom two rows until all their tiles are in the correct rows.

Phase 3: Order the tiles in each row
In this phase you will reorder each unsolved row by swapping adjacent tiles. You need at most 3 such swaps to solve a row. The worst case is when you have to swap the two outer tiles, for example 654 which is solved in three swaps for example like this: 654, 645, 465, 456.

1. Look at order of the tiles in one row, and if they are not in the correct order, determine which two adjacent tiles you would like to swap to improve the situation.
2. Cycle the bottom two rows until the two tiles you wanted to swap are at the right of the rows.
3. Perform the swap sequence to swap the two tiles.
4. Cycle the bottom two rows back so that the tiles are in their correct rows again.
5. Repeat steps a-d until the last two rows are solved.