Jump to content

Solve the Magic Square puzzle in a few minutes!


Aphelli

Recommended Posts

Q: What is this?

A: This is (supposed to be) a guide towards understanding the magic square puzzle.

 

 

Q: What do you mean, understand it? Solve it?

A: Yes. Sort of. No. My purpose here is to explain a method to think about this puzzle. If you understand it, actually solving an instance of the puzzle becomes rather easy: you will be able to quickly derive sequences of moves leading towards a solution. I use the word “derive” because it’s not quite automatic, but it’s not difficult all the same. 

 

 

Q: Does that mean you will not give me the actual solution?

A: There are several solutions and tutorials out there for the game’s original starting positions (which you can reset to, if I remember correctly). I aim to explain to you how to go about finding a solution from any starting position (it could even be a partially complete puzzle!). For this, I’ll take different starting positions from the game.

 

 

Q: I don’t care, I’ve done it once and now I have New Game Plus.

A: This is absolutely fair! Just remember that you have an option to stop fearing that puzzle.

 

 

Q: You’re not the first one doing this.

A: Indeed not. There’s a guide by Thiazzi which is certainly worth reading. But my method is different, and I believe that it is more flexible (and it produced shorter solutions). Moreover, it seems that these guide has not had the impact it deserved, given what Ame (the puzzle’s own creator!) said in her stream, about “people who were watching not being able to help her”. She succeeded without outside help, but I still think that another attempt to demythify this puzzle is worthwhile.

 

 

Q: Is this going to involve math? I don’t like math. Numbers make me itch. Equations give me nausea.

A: Well… yes and no. My method is definitely mathematical in its spirit. But if this question describes you, chances are that you don’t know what kind of mathematical concepts are involved. Which is completely fine! This isn’t a math class, and there are no prerequisites for this tutorial.

 

 

 

 

 

 

1°) The Rules

You probably know them already, but I think it’s worth recalling them.

We are given 18 digits in three rows of six: every digit between one and nine appears twice. For instance, a starting position could be (I didn't think about the pick at all; I don't think it's atypical in any way):

 

486411

323578

927659

 

The goal is to end up in a situation where

a)     The two 3x3 squares, left and right, contain every digit from 1 to 9 exactly once.

b)     In these squares, the sum of the digits on all four lines going through the center is 15.

c)     No digit occupies the same position in both squares, except maybe for the center.

 

Maybe b) is a little bit abstract: concretely, for the left square, the four sums that would need to be equal to 15 are 4+2+7, 8+2+2, 6+2+9, 3+2+3. The condition is (obviously) not satisfied.

 

The condition a) fails too, since the left square contains both 3, and the condition c) is also not satisfied, since the digit 4 has the same position in both squares.

 

So we need to change the grid. There are two kinds of allowed operations:

i.                 Shift any row leftwards, or rightwards.

ii.                Shift any column upwards, or downwards.

 

For instance, if you shift the second row rightwards, it starts from 323578 and becomes 832357: the rightmost digit goes to the left. Similarly, if you shift the last column downwards, it starts from 189 and becomes 918: the downmost digit goes all the way up. 

 

 

2°) Why do we need a guide?

Well, you can try solving the puzzle on your own! It’s not too difficult to get one square right, but you run into a major issue when trying to complete the second one: every move that gets you closer to completing the second square messes up the first one. So we can’t be straightforward; we need to be craftier.

 

Just to clarify for later: in a solved square, the 5 has to be in the center, and the two other numbers in every line must add up to ten. For instance:

 

368

159

247

 

 

3°) The Technique

To solve this puzzle, our main tool is the 3-cycle (which I will sometimes call "cycle" since we won't consider any other kind).

Please do not let this (admittedly ugly) name frighten you. It’s very simple: choose three spots in the grid, and then move them all around.

 

486411     >     476411

323578     >     823538

927659     >     927659

 

Note how all three bolded digits changed location – in a cycle – and no other digit did, hence the name. Not so scary now, is it?

 

Now, we can’t do just any 3-cycle (apart from a column shift) in one move, but let us assume, for a moment, that we could. Then we have a lot of possible actions, because there are so many available 3-cycles. In one move, we can move one digit (in fact, two, a lot of the time) of our choice to a location of our choice, and yet preserve (almost) anything we have already built: thus we can solve the puzzle one (or two) digits at a time.

 

Look: in the above configuration, we just need five 3-cycles (underlined indicate a cycle that was just moved; bold denotes the cycle that will move at the next step)!

 

486411     >     486411     >     486411     >     386411     >     386451     >     386431

323578     >     353278     >     353278     >     953278     >     951278     >     951258

927659     >     927659     >     927956     >     427956     >     427936     >     427976

 

Note that when you’re including two identical digits in a 3-cycle, it looks like one of them doesn’t move, which is often convenient.

The point of the first cycle is to put one 5 in the center, and put both 2 in correct positions.

The second cycle puts the 9 and a 6 in correct positions.

The third cycle puts the leftmost 3 and 4 in correct positions, and 9 in a promising one.

The fourth cycle brings a 1 in front of this 9 while putting the 3 in the second square, and the last cycle wraps the puzzle up.

 

Note that there’s no need to optimize anything or think three moves ahead here: you really can improve one step at a time (except at the end, technically – I’ll come back to it in the end later).

 

I invite you – for practice – to reconsider the starting position, and try coming up with sequences of 3-cycles that solve the puzzle.

 

Do you see now how using 3-cycles makes the puzzle drastically easier?

 

 

4°) How to do a 3-cycle?

But so far this isn’t concrete. We’ve pretended that we could do any 3-cycle we chose. But they’re not in the operations we’re allowed to do, so what was the point? The only 3-cycles we can apply are the column shifts, and they’re clearly not sufficient on their own for what we did in the second paragraph.

 

But these column moves still do something important: they allow us to move three tiles around, while leaving everything else in place.

 

The trick to do a general 3-cycle is the following:

i.                 Put the three digits in a column.

ii.                Shift the column upwards or downwards (whichever corresponds to what you want to do)

iii.               Rewind precisely what you did in step i.

 

Again, that’s a little bit abstract, how about some practice? Remember the first cycle: 

486411     >     486411

323578     >     353278

927659     >     927659

 

Here, the simplest way is to put everything on the second column. For instance, we can shift the fourth column up, then shift the first row leftwards twice.

 

This gives:

 

486411     >     486511     >     865114     >     651148

323578     >     323678     >     323678     >     323678

927659     >     927459     >     927459     >     927459

 

Now, we want the 5 to end up in the spot of the blue 2, so step ii. means shifting the second column downward.

 

651148     >     621148

323678     >     353678

927459     >     927459

 

In step iii., we rewind step i.: that means shifting the first row rightwards twice, then move the fourth column downwards.

 

621148     >     862114     >     486211     >     468411

353678     >     353678     >     353678     >     353278

927459     >     927459     >     927459     >     927659

 

 

For a little bit of practice, how about finding the sequences of moves for the second and fourth 3-cycles in the solution of 3°)?

 

Remember, these cycles are:

 

486411     >     486411

353278     >     353278

927659     >     927956

 

Solution:

Spoiler

Let’s put the three digits in the fourth column. So I do

Column 4 Up

Row 1 Right

Row 3 Left

Row 3 Left

 

We get

486411     >     486211     >     148621     >     148621     >     148621

353278     >     353678     >     353678     >     353678     >     353678

927659     >     927459     >     927459     >     274599     >     745992

so step i. is done.

 

The 9 needs to go to the spot occupied by the red 6, so step ii. is

Column 4 Up

 

148621     >     148621

353678     >     353978

745992     >     745692

 

 

Then step iii. is rewinding step i.

Row 3 Right

Row 3 Right

Row 1 Left

Column 4 Down

 

That is:

 

148621     >     148621     >     148621     >     486211     >     486411

353978     >     353978     >     353978     >     353978     >     353278

745692     >     274569     >     927456     >     927456     >     927956

 

 

 

and

 

386411     >     386451

953278     >     951278

427956     >     427936

 

Solution: 

Spoiler

We put the 3 in the fifth column (completing step i.), then, since the 3 needs to occupy the position of the 5, the fifth column goes downward (step ii.). Finally, we rewind, and we’re done. Formally:

 

Row 2 Right

Row 2 Right

Column 5 Down

Row 2 Left

Row 2 Left

 

Concretely: 

 

386411     >     386411     >     386411     >     386451     >     386451     >     386451

953278     >     895327     >     789532     >     789512     >     895127     >     951278     

427956     >     427956     >     427956     >     427936     >     427936     >     427936

 

 

5°) The Ending

Let’s sum up. While there are at least three numbers that are not at the correct spot, you can form a 3-cycle and get at least one of them (and often two) in the correct spot. But what happens at the end, if only two of them are in the wrong position?

 

Well, we have a problem, because we can’t switch two elements only by using 3-cycles. I’m not going to prove it, because I promised we wouldn’t get into math (and also because it depends on some details -- note, say, the first 3-cycle of the solution I gave for the invented starting point).

 

Fortunately, there’s a workaround: if you need to switch two elements, you can choose another pair to switch. Thus, instead of having two elements in the “wrong place”, you have four of them, and you can use a 3-cycle to put exactly one of the four elements in the right place. Then you’re left is just a 3-cycle.

 

This is a bit dry, so here’s an example:

 

836431

951258

427976

 

We have to switch the 8 and the 3 in the top left corner. We can’t really do that with 3-cycles, but what we can do is switch 8 and 3, and switch the underlined 6 and 4 as well.

 

So we do the 3-cycle 8 -> 3 -> 4 -> 8 (because the goal is to get one number at the right place; -> means “takes the place formerly occupied by”), and we reach

 

486431

951258

327976

 

Then all we have to do is the 3-cycle 3 -> 4 -> 6 -> 3, and we get

 

384431

951258

627976

 

So the puzzle is solved!

 

 

There's also another way: we can do a 3-cycle with two identical digits being the same, for instance the cycle 8 -> 3 -> 3 -> 8 in

 

836431

951258

427976

 

 

 

That’s it, we’ve covered everything!

I hope this was clear enough and that you now feel ready to devise your own solution to the various puzzle positions you got in. If not, please tell me how I could improve this explanation. 

 

  • Thanks 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...