33

Well you probably already knew that this was coming after the last two puzzles :) I believe this is the most beautiful one.

You are given a 5x5 grid with 3 crosses as shown below. Each turn, you can select a cross and slide it along horizontally or vertically. It will continue sliding until it hits another cross or a wall. Can you get a cross into the centre square?enter image description here

Dmitry Kamenetsky
  • 35,897
  • 5
  • 66
  • 276
  • I like this puzzle, but was it really necessary to post a 3x3 version, then a 4x4 version, then this? – xnor Oct 19 '23 at 23:55
  • 6
    I liked these three puzzles AND I appreciate that they have varying degrees of difficulty from the easiest(3x3) to hardest(5x5). – Will Octagon Gibson Oct 20 '23 at 02:39
  • @xnor in hindsight this was probably overkill to make 3 puzzles. At the time I thought that 5x5 is not possible and was only going to do 3x3 and 4x4. – Dmitry Kamenetsky Oct 20 '23 at 07:11
  • 1
    Just in case anyone wants to generalize this: with 3 crosses in a 6x6 you can also move one to the center 4 squares by the same solution posted here. – quarague Oct 20 '23 at 10:45
  • 1
    Hey, I thought you might like to know that I made a little web browser game out of these 3 puzzles! https://vmi1489186.contaboserver.net/static/sliding-puzzle/ (licensed under CC BY-SA 4.0, like all stackexchange user content, and with credit given for the puzzle design, of course) – Oli Oct 30 '23 at 21:17
  • @Oli that is very cool! Thanks for making. If you want more levels then you can add walls that cannot move and change the starting ball locations. – Dmitry Kamenetsky Oct 30 '23 at 22:56

3 Answers3

27

I saw these questions late, so I decided to answer all 3 (3x3, 4x4, 5x5 grids) as well as the general case (nxn grids). The answer is

Yes (for any nxn grid)

Regardless of initial position, we can move the Xs upwards so we have them in the following set-up:

XXX......
.........
.........
.........
.........
.........

Then, we can shift this chain of Xs to the right by rotating the leftmost one each time:

.XX......
.........
.........
.........
.........
X........
.XX......
.........
.........
.........
.........
........X
.XX.....X
.........
.........
.........
.........
.........
.XXX....
........
........
........
........
........

Regardless of size of the grid, we can continue this process until the middle X is aligned with the middle column:

...XXX...
.........
.........
.........
.........
.........

Then, we can move the middle X downwards. The leftmost X and bottom X will then be used to put the third X on top of the X in the bottom middle, which we can do repeatedly:

...X.X...
.........
.........
.........
.........
....X....
...XX....
.........
.........
.........
.........
....X....
...X.....
.........
.........
.........
....X....
....X....
...X.....
.........
.........
.........
....X....
........X
...X....X
.........
.........
.........
....X....
.........
...XX....
.........
.........
.........
....X....
.........
...X.....
.........
.........
....X....
....X....
.........

By continuing this process, we will end up with an X in the center of the grid (if n is odd) or 2 Xs in the center of the grid (if n is even).

...X.....
.........
....X....
....X....
.........
.........
Bryce
  • 559
  • 2
  • 7
  • 3
    great solution to the general case. Thank you. – Dmitry Kamenetsky Oct 20 '23 at 07:13
  • 1
    This also means that any square is reachable in any NxN grid. Quite amazing – Dmitry Kamenetsky Oct 20 '23 at 09:02
  • 2
    No problem @DmitryKamenetsky! I'm pretty confident that the reason for this result is that since the grid is 2-dimensional, 3 Xs are needed to access any square (since 1 X is needed to "fix" each dimension and the last X is used to move around). I think the more interesting result would be checking if k+1 Xs are needed to access any square in the k-dimensional case! – Bryce Oct 20 '23 at 13:04
  • Wow I haven't even considered higher dimensions! Can we get into the centre with 4 Xs in a 5x5x5 cube? – Dmitry Kamenetsky Oct 20 '23 at 14:17
  • 1
    @DmitryKamenetsky See this comment: https://chat.stackexchange.com/transcript/message/64600130#64600130 – GentlePurpleRain Oct 20 '23 at 16:40
22

The answer is (maybe surprisingly)

Yes


Lets reverse engineer the problem:

We need to get to this position (other orientations obviously fine):

enter image description here

so we can slide the X into the middle. This means we have one spare X to set this position up

So we can do so by doing the following:

enter image description here

For a total of 14 moves

Beastly Gerbil
  • 58,036
  • 8
  • 166
  • 314
6

Optimal solutions (fewest moves, confirmed via code) for odd grids.

For the 5x5 grid:

12 moves
enter image description here

For the 7x7 grid:

19 moves
enter image description here

For the 9x9 grid:

26 moves
enter image description here

For larger grids:

11x11: 33 moves
13x13: 40 moves
15x15: 47 moves
and so forth.

Daniel Mathias
  • 14,926
  • 2
  • 30
  • 62