I did it! After weeks of alienating efforts, I did it. I made it to the end of the 2048 tile game.
It’s the Internet sensation of these days. It’s a game played on 4×4 grid, with numbered tiles. At each stage, you slide tiles in any of the four directions of the screen (up, down, left and right). If two tiles of the same number fall onto one another, then they merge into a tile whose number is the sum of the tiles’ numbers. Once tiles have slid and merged, a new tile pops up at a random free location of the grid. With 10% chance, it’ll be numbered 4. Otherwise, it’ll be numbered 2.
The best way to get them is to actually play the game. That’s why, if you’ve never played the game, I invite you to spend some time playing it right now (but try to stop before becoming completely addicted to it!).
In its basic version, the game stops as soon as you manage to create a 2048 tile. But, as a nerdy mathematician, it sounds way too arbitrary to me. So, I tried to go as far as I could. And, a few days ago, after weeks of effort, I did it! I’ve reached the mathematical end of the game that’s displayed on the right! This means that, even in principle, you cannot go further than this.
The game raised numerous intriguing questions about the underlying mathematics of the game. From induction to isomorphisms, including geometric sums, topology, probability and optimization, these mathematical questions are these I address in this article!
Powers of 2
Let’s start with the simple observation that all tiles are powers of 2.
What seems obvious still needs to be proved in mathematics! And your repeated observations that all the configurations you’ve ever seen only contain powers of 2 have little mathematical bearing. We’re not doing physics here!
A simple proof is by mathematical induction. More precisely, we’ll show that at any stage of the game, all tiles are powers of 2.
To prove that all tiles are powers of 2 by mathematical induction, it suffices to prove two simpler points:
- At first, all tiles are powers of 2.
- Assuming that, at some stage, all tiles are powers of 2, then, at the next stage, all tiles will still be powers of 2.
Point 1 fact is pretty straightforward. Indeed, at first, the only tile on the grid is the initial 2s or 4s we start with. And, as we all know it, 2 and 4 are powers of 2. More precisely, we have
In point 2, we assume that at a given stage, all tiles are powers of 2. We need to show that no matter which move we then do, all tiles will still be powers of 2. The key to show that is to notice that all tiles that can be created in a move are either the randomly generated new tile or a tile obtained by combining two identical tiles. Yet, in the first case, we have see that tiles randomly generated are either 2 or 4 which are both powers of 2.
In the second case, the number of the newly generated tile is the sum of two identical tiles of the previous stage. Yet, we assumed that all tiles of the previous stage were powers of 2 (this is known as the recursion hypothesis). Thus, the two identical tiles that were added are of the form
Then, by mathematical induction, the proofs of the two points imply what we’ve wanted to prove all along. Namely, we now have a complete proof that all tiles are always powers of 2.
Geometric Sums
Let’s now discuss the mathematical end of the game. In the introduction, I claimed that the configuration I reached couldn’t be surpassed. But before getting there, let me compute the sum of all tiles of that configuration.
As a lazy mathematician, I don’t like doing long additions… So let me show you a trick to easily compute the sum of this all.
Let me add
Amazingly, our computation simplifies to the simple addition
It’s the magic of so-called geometric sums. Our geometric sum is
You can see a pattern appearing, which hints at
In fact, the pattern is so strong that it can be generalized for powers of 3, powers of 4, or in total generality, for powers of any complex number
The Mathematical End of the Game
Now, to prove that the configuration of the introduction is the mathematical end of the game, it suffices to show that the sum of tiles reaches its maximum in the configuration I got. In other words, let’s show that tiles cannot add up to more than
Notice that, after every move, the total sum of tile numbers increases by the number of the new randomly-generated tile. This new tile is either 2 or 4. So, the total sum of tile numbers increases by steps of 2 or 4. So, to get to a configuration whose total sum of tile numbers is more than
It all has to do with the decompositions of these numbers as sums of powers of 2. To have the tiles fitting in the bounded 4×4 grid, we need to find decomposition as efficient as possible, in the sense that we want to write the sum of tile numbers with the smallest possible number of powers of 2.
It’s easy to see that, in any most efficient decomposition, powers of 2 must appear only once. Indeed, otherwise, we can just combine 2 identical powers of 2 into their sum, hence yielding the same sum with one less tile.
Let’s take
Notice that, once tiles of 2 and 4 subtracted, we need to obtain a multiple of
Exactly! In fact, the most efficient decomposition of
The most efficient decomposition of
The Probability of Getting There
Some of my friends pointed out that I was in practice mode with unlimited undos, and have pointed out that this is sort of cheating. Or, at least, this is making the game much much easier. It does. To the point that it is also mathematically impossible to get to the end configuration in the normal mode with 5 undos.
Well, nearly. What I’ll claim is that within our lifetime, no human (nor computer!) can ever get there without unlimited undos. Or, at least, it is overwhelmingly unlikely for anyone to get there.
For a start, let me point out that
First, we must have gone through
Yes. But our argument for
It does! This yields a probability of at most one out of
For sure, humans can’t. Even if every human played one game every day for 100 years, we couldn’t play about
If the actual probability of a game being playable to the mathematical end is probably overwhelmingly less than one out of
Topology and Paths
So far, our discussions have mainly about the numbers underlying the game. We focused on what the tiles are. But any player of the game would notice that this is far from being the only thing that matters in the game. Something else is at least as important.
I’m hinting at the positions of the tiles. To go far in the game, tiles must be nicely ordered on the 4×4 grid. And this is a matter of topology.
Topology literally means the study of location.
There is a subtle, but crucial difference between topology and geometry. While geometry is concerned with actual shapes of objects, its angles and distances, topology is blind to these concepts. Instead, topology merely focuses on how the components of objects are connected. In our case, the components of our game are tiles, and it is important to see how they are connected to one another. In fact, if you look at the mathematical end of the game I’ve reached, you can see that there is a clear pattern in the way tiles are connected.
Yes. And that’s a crucial feature you want to have when you play this game! Indeed, for two tiles to be combined, they need to be close to one another. Technically, they need to be on the same row or the same column, with no tile in between. So, obviously, the best way to make sure that two tiles can be combined is to have them touching one another. Similarly, we’d better have tiles which are meant to be combined eventually near one another. This means that
Exactly. So, eventually, we should have some sort of path from
Optimal Strategy
Now, in my experience, following the most stable of these paths is a great strategy. And the snake line seems quite stable.
What I mean is that we can maintain or get back to the snake line rather well despite the perturbation created by the randomly generated tiles. It’s a bit as if you driving a car and wind was blowing gusts left and right. Then, a flat large highway will be more stable than a tortuous mountain track.
Hummm… There’s a trouble here with the concept of “best” strategy. In fact, let’s listen to Steve Mould and James Grime discussing good strategies of the game:
So, importantly, there is uncertainty in the game. Namely, the randomly generated new tiles of each stage create an uncertain environment. In such uncertain environments, there are several possible concepts of optimality:
- Best-case optimality (this is unconventional…): The best strategy in the ideal case where randomly generated tiles always appear exactly where we’d like them too.
- Stochastic optimality (average): The strategy that works best in average.
- Robust optimality (worst-case): The best strategy that works in the worst case where randomly generated tiles always appear exactly where we wouldn’t like them to.
The best-case is basically the one I’ve been talking about so far. Whenever I didn’t like the location of the new generated tile, I just did undos until it was at a satisfying location. Now, since I got to the mathematical end of the game using the snake line strategy, I can guarantee that the snake line is a best-case optimal strategy!
It’s the one you should be using when playing according to the classical mode with limited undos. A stochastic optimal strategy should then ensure you the maximality of your average score at the end of the game. But, like often when it comes to stochastic optimization, determining the stochastic optimal strategy is very, very, very difficult.
Indeed. Quite often in optimization research, stochastic optimization is simply too hard to handle. The next best thing is then to turn towards robust optimization, which has been very successful in many applications. However, in our case, as hinted at by Steve Mould, robust optimization is probably way too conservative an approach. It makes sure that we can get far enough, but does not aim at going very far…
What I mean is that the worst-case imagined by robust optimization is in fact terribly unlikely that it is not relevant. It’s easy to get a feel for that! Try to play this version of the game, where the computer will always try to put you in this worst-case. As you’ll see, it’s a very different game that you’re suddenly playing! In fact, the best I’ve had in this version is the figure on the right…
Isomorphism
In my research lab where we often play card games, I’m kind of known for abusing of my favorite mathematical word: Isomorphism. How funny was it for me that James Grime used it just as I would:
Two games are said to be isomorphic if they are essentially the same. So for instance, if you replaced all classical tiles
Yes. Conversely, while the hard version of the game where the computer plays against you has the same visual representations as the classical 2048 tile game, it is definitely not isomorphic to the classical game. In particular, any good strategy in the classical 2048 tile game doesn’t translate into a good strategy of the difficult version. Similarly, the Fibonacci version is not isomorphic to the classical 2048 game, as the new rules of tile combinations completely mess up topological considerations!
There are other underlying isomorphisms in this game. Namely, if we rotate the game by 90° all along, then the game is unchanged a priori. Similarly, albeit trickier, if we permute up and left while permuting down and right, then the game is still essentially the same. In particular, in the configuration on the right, all moves are isomorphic. You can either go up or left, and both moves are essentially the same.
It is! Symmetry is the geometrical word corresponding to the more fundamental concept of isomorphism. Two objects are symmetric if they are (geometrically) essentially the same.
Yes it will. But given that this next tile hasn’t appeared yet, and since our uncertainty about where it will appear respects the symmetry too, the two moves are in fact symmetric prior to when the next generated tile appears.
Let’s Conclude
The 2048 tile game raises plenty of interesting underlying mathematical questions. Maybe not as interesting as physics or chemistry according to some professors though…
With all due respects to these professors, I personally find the 2048 tile game very (too?) addictive. And it’s also mathematically intriguing, as a deep understanding of the game takes us through the concepts of induction, geometric sums, probability, combinatorics, topology, optimization, game theory and isomorphism we have discussed in this article. In fact, I find the game so puzzling that, I’ll admit it, I’ve already dreamt of it…
Hello just wanted to give you a quick heads up. The text
in your content seem to be running off the screen in Safari.
I’m not sure if this is a formatting issue or something
to do with web browser compatibility but I figured I’d post to let
you know. The design look great though! Hope you get the problem solved soon. Kudos
I blog quite often and I really thank you for your content.
Your article has really peaked my interest. I’m going to
book mark your site and keep checking for new details about once a week.
I opted in for your Feed as well.
continuously i used to read smaller content that as well clear their motive, and
that is also happening with this article which I am reading here.
Your way of explaining the whole thing in this paragraph is genuinely pleasant, every
one can effortlessly know it, Thanks a lot.