Part III: Spiral and Cycle
Well, yay! Now we have a solid 3-cycle for all $n \geq 4$. Smaller $n$ values are probably special cases. So we're gonna call $n \geq 4$ the general case. Have we basically solved the general case? No, because we only have a specific 3-cycle algorithm, i.e. we have an algorithm that can only cycle three numbers in these three set locations. I want to be able to choose any three numbers I want and cycle them. What do I do now?
The idea is that I'm going to use my specific 3-cycle to create my general 3-cycle algorithm. Here's basically how it's going to work:
- Choose 3 numbers you want to cycle.
- Move them to the 3-cycle squares (the three squares that you know can be 3-cycled). It's ok if other numbers' positions are ruined.
- Execute the 3-cycle.
- Undo the moves in step 2.
This works because step 3 only really affects 3 squares, and step 4 will undo all the weird "side effects" of step 2.
So, to do a general 3-cycle, all we have to do is figure out how to do step 2. That is, we need to be able to send any three numbers to any three squares we want. And, to do this, we are allowed to ignore all the other numbers, they don't matter anymore.
That's kinda hard. Let's try something easier: Can we send any single number to any square we want? As before, all the other numbers don't matter, I just want to be able to find a sequence of moves that can move some number to whatever square I want.
The solution to our predicament is the Spiral algorithm. Spiral can send any number we want to any square we want (while obeying PRs):
How would we come up with an algorithm like Spiral? Once again, we need to simplify our job. Can I send any number I want to the center square? If I can figure out how to do that, then I'm done! All I have to do is:
- Find the moves I need to move my number to the center.
- Find the moves I need to move the number in the goal square to the center.
- Do the moves in step 1, then do the moves in step 2 in reverse.
This will bring my number to the center, and then the goal square.
Now I just need to figure out how to bring my number to the center. The idea is that I'm going to come up with a nice procedure that will bring my number closer to the center. Then if I keep doing that, my number will keep getting closer and closer to the center. Eventually, it will be right at the center!
Welp, here's my Spiral algorithm:
- Bring my number to the lower-left quadrant of the rotating Y block.
- Rotate X.
- Repeat until at center.
That's it! Let's see how this plays out.
First, I keep rotating Y until my number is in the red region, which is the lower-left part of the rotating Y block.
Now, I rotate X just once.
If I keep doing this, my number eventually reaches the center. It kinda looks like a spiral. That's why I call this Spiral.
Question of the Day: Why does this work? Why is it that if I do those steps, the number must get closer to the center?
We need to figure out when the distance changed. It's when I did the X move:
The distance changed from $d$ to $d^\prime$. I need to prove that $d^\prime < d$.
I only need to focus on the X move. Also, I marked the two centers of the board as $c_x$ as $c_y$. This will be very useful.
I don't really care about the grid anymore. To help me out, I drew a circle at $c_y$ with radius $d$, because I know my number starts on the lower-left arc of this circle (in bold).
At this point I guess I can throw out the whole board too.
Next I needed to get rid of that X move and turn it into math somehow. Here, I turned it into an isosceles right triangle. This makes sense because during the X move, the distance to $c_x$ doesn't change, and it's a 90 degree turn.
Here I'm going to do something tricky. I'm going to make a new point called $c_y^\prime$. It's the point you get when you rotate $c_y$ 90 degrees clockwise around $c_x$. But why would I ever make a new point? Well look:
These two angles I marked are equal, right? You get both of them by subtracting a common angle from a right angle. But then...
Amazing, these two triangles are congruent! That means...
This missing length from $c_y^\prime$ to the number must be the same as $d^\prime$ by my congruent triangles! Now let's erase a bunch of the noise in my diagram:
Now I'm going to assume that each square's side length is one. Then the distance between $c_y$ and $c_y^\prime$ must be $\sqrt{2}$.
Finally, I will mark an angle $\theta$:
Remember that my number started on the lower-left arc of the circle, so that's why $\theta$ can't be more than $45^\circ$.
Ok I'm lost, what were we doing again? Right, we wanted to prove that $d^\prime < d$. At this point, we have an angle, two adjacent sides, and we need to compute $d^\prime$... I wonder how we can do that...
$$\Huge \text{Surprise! It's the Law of Cosines!}$$
By the Law of Cosines:
$$d^\prime = \sqrt{d^2+2 - 2\sqrt{2}d\cos\theta}$$
We need to prove that this is less than $d$, or:
$$\sqrt{d^2+2 - 2\sqrt{2}d\cos\theta} < d$$
Now we just need some nice algebra to manipulate this:
$$d^2+2 - 2\sqrt{2}d\cos\theta < d^2$$
$$2 - 2\sqrt{2}d\cos\theta < 0$$
$$2 < 2\sqrt{2}d\cos\theta$$
$$1 < \sqrt{2}d\cos\theta$$
$$d\cos\theta > \frac{\sqrt{2}}{2}$$
How do I prove this? Well I know two things:
- $d>1$. Otherwise, the number is already at the center, so the algorithm would have stopped already.
- $\cos\theta > \dfrac{\sqrt{2}}{2}$. That's because $0 < \theta < 45$.
If I multiply these two things, I get exactly $d\cos\theta > \dfrac{\sqrt{2}}{2}$. QED.
- So, the distance to the center decreases with every iteration.
- Thus, the distance to the center is eventually zero (because there are a finite number of possible distances).
- Therefore, Spiral is a terminating algorithm, and we have an algorithm that can send any number to the center.
- Ergo, we have an algorithm that can send any number to any square.
Yay! Wait now what?
Ok so, we wanted to be able to send any three numbers to any three squares. What we can do now is send any one number to any one square. We have to use Spiral three times, somehow, without messing up every previous number. But how?
Before we go on, I want to look at one more algorithm, called Cycle. It's defined as:
$$(YX)^4 = YXYXYXYX$$
It's a very simple 8-move algorithm. What does it do? Well imagine that there's some sort of "conveyor" belt running around the board:
Cycle will move all the numbers $n-3$ squares "counter-clockwise":
It's actually not too hard to prove that it does this for all $n$. Something we call the "cyclic order" of all the numbers in the belt stays the same every time we do $YX$, and using some math we can find out how much each number moves after every $YX$.
Why is Cycle so important? Because it doesn't move a lot of numbers. That will give us more maneuverability. And with that, we're ready to describe...
Part IV: The Spiral-Cycle Algorithm
The Spiral-Cycle Algorithm sends three numbers to any three squares I want. It is a combination of Spiral and Cycle. Very similar to the Spiral algorithm, this won't happen directly. Instead, I will choose three set squares, and show that I can always move any three numbers to them. I will call these set squares the intermediate squares.
My ultimate plan will be:
- Use Spiral-Cycle to find a sequence of moves that will send my three numbers to the three intermediate squares.
- Use Spiral-Cycle to find a sequence of moves that would send the three numbers in the goal squares to the intermediate squares.
- Execute the moves in step 1, then execute the moves in step 2 in reverse.
This will send my three numbers to the three goal squares via the intermediate squares. Now I just need to choose my intermediate squares and figure out how to get my numbers there.
For odd $n$, I choose these three:
For even $n$, I choose these three:
In both cases, the first of my intermediates is in the upper-left corner, and the third intermediate is at or close to the center of rotation of $X$. The third intermediate square is as close as possible to the first one, in the first column. In the odd case, that means it has to be two squares below because of PRs (if $n$ was odd and I tried to cycle three numbers that weren't in the same parity, it would be impossible).
I will now describe, roughly, the Spiral-Cycle algorithm:
- Use Spiral to move the first number to the top-left.
- Use an alternating Spiral to bring the second number to the center of rotation of $X$ for odd $n$, or the upper square in the center for even $n$.
- If the first number was moved to the bottom-left due to the previous step, move it back to the top-left via $X^{-1}$ for odd $n$, or $X^{-1}Y^{-1}$ for even $n$.
- Use an alternating Spiral to move the second number to bottom-right corner for even $n$, or the square above that corner for odd $n$.
- If the first number was moved to the bottom-left at the end of the previous step, execute $X^{-1}$ to move it back to the top-left corner.
- Execute $XY^{-1}X^{-1}$. This will bring my second number to the second intermediate square.
- If the third number is now in the leftmost column, then move it out using $XY^2XYXY^{-1}X^2Y^{-1}XY^{-1}X^{-1}$ for odd $n$, or $XY^2X^{-1}Y^{-1}XY^{-1}X^{-1}$ for even $n$.
- If the third number lies somewhere on the bottom row or right edge, execute $Y$ until it does not.
- Run Spiral alternated with Cycle to get the third number to the center of rotating of $X$.
- Execute Cycle if you need to and terminate.
Obviously this is confusing, especially since there are two new things: An "alternating Spiral", and "Spiral alternated with Cycle". Let's go over both.
- In a normal Spiral, every iteration starts by moving the number to the lower-left quadrant and then executing $X$. In an alternating Spiral, it is the same procedure, but every other iteration I instead move the number to the upper-left quadrant and then execute $X^{-1}$. Basically, I'm doing a flipped version of Spiral every other time.
- In a Spiral alternated with Cycle, I do an reverse Cycle before every time Spiral wants to use an $X$ move, and then do a Cycle before every time Spiral wants to use a $Y$ move.
These extra things are here to make sure the numbers we place stay where they are. Let's see how this works in practice.
First I do a Spiral to move my first number to the first intermediate.
Now I'm looking at the second number. Here it looks like I'm doing Spiral normally... but once I move $X$, something awful happens:
Oh no! The first number moved away to the bottom-left. Now I'm going to flip Spiral, so next time it will move back. Here I'm going to move my second number to the upper-left quadrant this time.
Now this time, I'm going to do $X^{-1}$ instead of $X$, and this will move the first number back to where it was.
I just have to keep doing this until my Spiral is done, and my second number ends up here:
I do $XY^{-1}X^{-1}$, and my second number can now join the first number happily:
Now I just need to somehow get the third number to the center...
Here I'm basically doing Spiral normally, except now I'm pretty much always using the top-left quadrant (always flipped version), because this quadrant doesn't intersect with Cycle's belt.
After I move my third number inside the quadrant, the next step of Spiral would be to execute $X^{-1}$. But this is terrible, because both of the first two numbers will move away, and this time that's basically unfixable. The trick is to now use Cycle in reverse to hide my first two numbers in the last column:
Now I can freely move the $X$ rotating block without moving the first two numbers.
Now the next step in Spiral is to move $Y$ until the number is in the upper-left quadrant again. But doing any $Y$ moves will move my first two numbers again. That's why now I have to use Spiral, which will move my two numbers back to where they were:
Now I am free to use the rotating $Y$ block! Rinse and repeat until my third number is where it needs to be:
We made it! That's the Spiral-Cycle algorithm. Let's recap:
- We now have an algorithm that can send any three numbers to any three squares, subject to PRs.
- So, we can always send any three numbers to three squares that we know can be 3-cycled.
- Thus, any three numbers can be 3-cycled, respecting PRs.
- Therefore, we can execute any even permutation.
- Ergo, the NRP is solved over all $n \times (n+1)$ boards with $n \times n$ rotating blocks for $n \geq 4$.
What about boards that have more moves than those like $n \times (n+1)$ boards with $n \times n$ rotating blocks? Like, maybe a $6 \times 6$ board with $4 \times 4$ rotating blocks? How can we extend our solution from the "hardest NRP" to the very general case?
As it turns out, it's not too bad! I will leave out the details, so treat it as a fun little exercise to the reader. Remember, we basically have the ability to execute any permutation we want within a $n \times (n+1)$ board with $n \times n$ rotating blocks. How can we use this fact to solve, say, a $(n+1) \times (n+1)$ board with $n \times n$ rotating blocks? Here are some cool ideas:
- Like before, if we can show that we can do any 3-cycle, we're done. Can we somehow extend the Spiral-Cycle algorithm?
- Could something similar to a Bubble Sort algorithm work?
- Can we use an inductive argument?
That's gonna wrap up the general case. Let's move on to...
Part V: Special Cases
We'll cover all the easy ones first.
$2 \times n$ board with $2 \times 2$ rotating blocks, $n \geq 4$
Super easy. All initial configurations are solvable. Take any $4 \times 2$ sub-board, and label the possible moves from left to right $X$, $Y$, and $Z$. Then the following algorithm will switch two numbers:
$$XYZ^{-1}Y^2X^{-1}Z^{-1}YZ^2Y^{-1}$$
$m \times n$ board with $2 \times 2$ rotating blocks, $m,n \geq 3$
It's kinda funny that I'm considering the classical NRP as a special case, kinda because it is. Anyway, this is super easy. All initial configurations are solvable. Consider a $3 \times 3$ sub-board, and let $X$ rotate the lower-left $2 \times 2$ block, $Y$ rotate the upper-right block, and $Z$ rotate the lower-right block. The following algorithm switches two numbers:
$$XY^{-1}X^{-1}YZ$$
$m \times n$ board with $3 \times 3$ rotating blocks, $m,n \geq 4$
All numbers must start in the correct parity, and the initial configuration must be an even permutation. Nothing we didn't expect, so we just need a 3-cycle algorithm and we can leave. Let $A$ rotate the upper-left $3 \times 3$ block, $B$ rotate the upper-right block, $C$ rotate the lower-left block, and $D$ rotate the lower-right block. Then the following is a 3-cycle:
$$ADA^{-1}D^{-1}C^{-1}DA^{-1}D^{-1}AC$$
Those are all the easy cases. Now we move on to the scary cases.
$2 \times 3$ board with $2 \times 2$ rotating blocks
Out of the $6!$ possible permutations of the 6 numbers, only $5!=120$ are actually solvable configurations! Not easy to prove. Fortunately, Jaaps Scherphuis solved this special case as it appears a lot in Rubik's Cube solving. Here are his proofs:
https://www.jaapsch.net/puzzles/pgl25.htm
$3 \times 4$ board with $3 \times 3$ rotating blocks
This one I had to tackle myself. It's really shocking. Since rotating block size is odd, numbers stay in their own parity, so you'd think that there are $6! \cdot 6!$ possible solvable configurations, right?
Oh no. Only $6!$ are solvable.
Exactly. That means that if you solve the numbers in one parity, the size numbers in the other parity will automatically solve themselves. How the heck would you prove this?
Honestly I have no idea how I thought of this. I constructed two movement-graphs:
Ok let's dissect this:
- Every $3 \times 4$ grid is a possible state of the board in terms of either the red lines or the blue lines I'm looking at.
- Every red or blue line represents a pair. A pair is a set of two connected numbers/squares. The two numbers will stay connected as you move them around. It's like a very stretchy rope.
- All the boards with a red line depict every possible single pair between two numbers, within the even parity. That means we're only considering pairs between numbers within these squares:
- All the boards with the blue lines depict every possible way to pair up the six numbers in the other parity into three pairs. In other words, it's every way to partition the white squares in the picture above into sets of two.
- Every black line between two boards is just a move. One board is before the move, and the other is after a move. It's either an $X$ move or a $Y$ move. Each move will move the pair(s) around.
You probably noticed this already, but the really importantly cool part here is that the two graphs look the same. In math speak, they're basically isomorphic structures. (You might be asking yourself if the moves between the boards are the same in each graph. You can verify that for yourself.)
So what does this mean? Let's look at this sort of pairing:
If you look carefully, these are two corresponding pairings according to the two graphs I made. That means that no matter what moves I make, if I know where the red pair is, I know where all the blue pairs are. I might not know which blue pair contains which numbers, or what order the numbers are in, but I just know where they are.
That means, if I make a sequence of moves so that the red pair returns to where it started, the blue pair must stay the same.
Using the specific pairing locations in the picture above, this means that no matter what moves I make, if the numbers in the top-left and bottom-left end up in the top-left and bottom-left (i.e. red pair stays the same), then I know instantly where the blue pairs are. Since two paired numbers stay paired, that means that if I also know the number in the middle-left square (in between the two red-paired numbers), I must also know the exact identity of the number in the square that it's paired with, which is the number in the center of rotation of Y.
This is really weird to think about but really important so I'm going to rephrase this. If I know the three numbers in the left column, and establish a system of pairs as in the diagram above, then:
- The number in the middle of the left column is always bound (paired) to this mysterious unknown number.
- If I make some moves that keeps the red pair where it is, it will also preserve the blue pairs.
- If the number in the middle of the left column stays there, then that makes the blue pair from that square to the center of Y unique.
- That means that in that case, the number in the center of Y is still the mysterious number.
- In other words, if I make a bunch of moves that doesn't change the three numbers in the first column, it also won't change the number in the center of Y. So the number here is actually unique.
- To rephrase, if you tell me the identities of the numbers in the first column, then there is only one possible number that could be in the center of Y, if it exists.
- Therefore, given the numbers in the first column, I can deduce the number in the center of Y.
Lemma: The number in the center of rotation of Y is uniquely determined by the numbers in the first column.
How would I "deduce" it? Kinda by cheating. Let's say you told me the numbers in the first column were 6, 7, and 8. Basically we now play the NRP starting from a solved board, and cleverly make moves so that 6, 7, and 8 make up the first column.
I see that the number in the center of Y is 5. So, it's a possible number that could be there given the 6, 7, and 8. But it's also the only possible number that could be there, since it's unique. Therefore, we "deduce" that the only possible number that can be there is 5, given that 6, 7, and 8 are in the first column.
Is there a neat formula you can follow instead, so you don't have to physically play the NRP to find it out? Well, you could kinda use the two movement graphs to figure it out a bit quicker, but besides that I honestly don't know.
Anyways, the result we have now is really powerful. It's basically going to help limit the number of solvable configurations. In fact, I will now prove the following:
Theorem: Suppose the left column is solved. Then the entire board will be solved via $Y$ moves.
In other words, once we solve the left column, there are only four possible configurations left! And, one of them is the solved board, and we just have to keep rotating Y to get it!
If you think about it, it suffices to prove that once the left column is solved, and the number 2 is solved, the whole board is solved. That's because saying that the number 2 is solved will "lock" the correct rotation of Y, so everything else would indeed be solved.
Ok, so we're assuming the left column is solved, and the number 2 is solved.
Using the Lemma, the 7 is already solved, because we know the three numbers in the first column, and therefore "deduce" the 7, so that's good.
What happens if we put the 2 in the middle-left instead of the 5? What can we "deduce" will be in the center of Y?
Welp, looks like it's 12. So given the 1, 2, and 9, the location of 12 is fixed/unique. Now I "know" where 12 is, and undo my moves. We "deduce" that the 12 was solved:
What's our next conquest? Now we have to use a flipped version of our lemma, i.e. start using the right column and "deduce" the number in the center of X.
By making the right column 1, 2, and 5, I "deduce" that the number in the center of X must then be a 6. That means that the 6's location is fixed too now.
I'm excited! What if I now use the 1 with the 6 and put the 7 in between?
4 is solved!
Only one number left in this parity, so 10 is solved!
You can keep going by attacking the last three squares with the lemma, but I'm gonna cheat. If we do $Y$ and then say that the configuration we get is the solved position, then all our previous logic applies. That means that any number that could end up in the center of X, where the solved 6 was, must be solved. In other words, since the 6 is solved, the other three numbers are solved as well.
We're done! That means the entire board is determined by just the first column!
What does that mean? Let's count the number of possible configurations based on this. There are six choices for the top-left number, then five choices for the bottom-left number. There are also six choices for the number in between. In all, there are $6 \cdot 5 \cdot 6 = 180$ choices for the first column. Then there are four rotations of Y left, and so there are a total of $180 \cdot 4 = 720$ possible solvable configurations...
...and $720$ is $6$ factorial!!! We did it! By a counting argument, we proved that solving one parity must solve the other parity automatically. Black magic huh?
Conclusion
So yeah. We completely solved the Number Rotation Puzzle. Completely.
We've figured out all the possible solvability conditions, exhaustively. And for the rest, we've basically derived a very long and convoluted solving algorithm to solve any board that satisfies our parity restrictions. And, we cleaned up the special cases, some of which were rather unruly. We did it all with an amazing combination of abstract algebra, number theory, combinatorics, and even geometry and computer science.
I think we did more than that though.
The NRP is scary. Daunting. When I first imagined something like $10 \times 10$ rotating blocks, or even puny $4 \times 4$ rotating blocks, I was convinced that it wouldn't be humanly possible to figure out. And for sure, the rectangular board case would be completely impossible to even think about. With raw motivation and determination, I proved my past self dead wrong.
We managed to figure it all out using just simple, beautiful ideas. I contend that no advanced mathematics was done in the process. Not a single integral or summation, and no sight of a matrix or even a group. Math doesn't have to be scary or hard. That's not what it's about.
In light of this, I believe my solution tells many stories. For one, it's a classic story of determination. Second, it shows that amazing things can be done with simple things.
Most importantly, I believe that this is a testament to my strongest belief: That math is just all puzzles in the end. Yes, we solved a puzzle using math. But in a sense, you could say we tackled a math problem in the same way that we would solve a puzzle. We found a starting point and worked our way forward using clever arguments, wrestling the problem until the end.
Overall, it's been a crazy journey for me, and thanks to Regeneron, the end of this puzzle was a new beginning, and it gives me a lot of hope for my future, my passion for math, and my passion for puzzling.
Thanks for reading, y'all.