Teaser 2878: Magic slides
From The Sunday Times, 19th November 2017 [link] [link]
I have a toy consisting of eight tiles that can move by sliding them around a three-by-three frame:
At any stage a tile adjacent to the space can slide into that space. I gave the toy to my grandson in the state illustrated and after some moves he presented it back to me with the space once again in the bottom right-hand corner but with the “2” (amongst others) not in its original position. Furthermore, his arrangement had some “magical” properties: each row, each column, and the diagonal from bottom left to top right all added up to the same total.
What was his arrangement?
[teaser2878]

Jim Randell 9:47 am on 20 January 2022 Permalink |
We’ve looked at sliding puzzles before. See: Enigma 1444, Enigma 106, Enigma 1210, Enigma 1160, Enigma 588.
In order for a position to be reachable the number of “inversions” (pairs of tiles that are out of order) must be even.
This Python program runs in 111ms.
Run: [ @replit ]
from enigma import (subsets, irange, all_same, printf) # fill out the grid for (A, B, C, D, E, F, G, H) in subsets(irange(1, 8), size=len, select="P"): # B cannot be 2 if B == 2: continue # check the magic lines if not all_same( # rows A + B + C, D + E + F, G + H, # columns A + D + G, B + E + H, C + F, # diagonal C + E + G, ): continue # the number of inversions must be even n = sum(i > j for (i, j) in subsets((A, B, C, D, E, F, G, H), size=2)) if n % 2 != 0: continue # output solution printf("{A} {B} {C} / {D} {E} {F} / {G} {H}")Solution: The arrangement was:
And we can use the sliding puzzle program I wrote for Enigma 1444 [link] to verify that there is a sequence of moves that produces the required arrangement:
LikeLike