Sunday Times Teaser 2878 – Magic Slides
by Victor Bryant
Published November 19 2017 (link)
I have a toy consisting of eight tiles that can move by sliding them around a three-by-three frame:
1 2 3
4 5 6
7 8
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?
One Comment
Leave one →
-
Brian Gladman permalink12345678910111213141516171819from itertools import permutations# valid solutions are even permutations of the original positiondef is_even_perm(p):return not sum(p[i] > p[j] for j in range(8) for i in range(j)) & 1# permute the tile positionsfor p in permutations(range(1, 9)):# tile 2 must moveif p[1] != 2:# create the row, column and backward diagonal sumssums = [p[0] + p[1] + p[2], p[3] + p[4] + p[5], p[6] + p[7],p[0] + p[3] + p[6], p[1] + p[4] + p[7], p[2] + p[5],p[2] + p[4] + p[6]]# all the sums must be equal to 12if set(sums) == {12} and is_even_perm(p):print('', *p[0:3], '\n', *p[3:6], '\n', *p[6:], '\n')