# 2048: How Many Fours?

### Problem

You have just completed a game of 2048, and you want to know what percentage of initial tiles were fours. How can you do so?

### Rules

First, the rules of 2048. In its basic form, this app consists of a 4×4 grid containing some tiles. On a turn, the user slides one of the four cardinal directions, and all tiles move until they have to stop. Tiles stop when they meet a wall or another tile; if two meeting tiles have the same number, they merge, and their new label is the sum of their tiles (that is, the next higher power of 2). Then the app randomly places a new 2 or 4 tile (what I’ll call an initial tile) somewhere in an empty cell. As the name suggests, the goal is to create a tile with 2048 on it (which is done by merging to 1024 tiles); the game is lost if you fill the grid and can’t merge any more cells. Whenever you merge two cells, you get the number of points equal to their sum, but you don’t get points for the initial tiles.

### Solution

Let us start with the assumption that only 2s are placed as initial tiles. That means that all tiles with greater numbers are the result of scoring plays. How can we figure out how much each tile is based?

Obviously, a 4 has a total contribution of 4 points. An 8 has a total contribution of 8 points in itself, and then 4 + 4 points for each 4 tile, for a total of 16. A 16 is worth 16 + 16 + 16, or 48 points.

We could continue on in this way, working out values all the way up to 2048 (and beyond); we could look for a pattern in the numbers and create a formula that way; or we could use recursive algebraic techniques.

I’ll use the third strategy. Given a tile with $$2^n$$ on it, its total point contribution $$P_n = 2^n + 2P_{n-1}$$. Meanwhile, $$P_{n-1} = 2^{n-1} + 2P_{n-2}$$, so  $$P_n = 2^n + 2(2^{n-1} + 2P_{n-2}) = 2^n + 2^n + 2^2P_{n-2}$$. A pattern emerges: $$P_n = (n-1) \times 2^n$$. That is, we will be repeating the $$2^n$$ term $$(n-1)$$ times.

This matches what we see using the second strategy: $$P_2 = 4$$, $$P_3 = 8 + 8$$, and $$P_4 = 16 + 16 + 16$$.

From here, we can then use the final state of a 2048 board to calculate what the score would have been if only 2s were used as initial tiles. For instance, $$2048 = 2^{10}$$, so a 2048 tile would be worth $$10 \times 2^{10} = 20480$$ points. The final score will be less than the sum of these values (not including the 2s), though, because some of the initial tiles are 4s.

Calculating the number of 4s is straightforward: Take the maximum score and subtract the actual score, then divide by 4.

To determine the number of 2s, we need to calculate the maximum number of 2s and then adjust based on the initial 4s. For each tile on the board, divide by two to get the number of 2s needed to make that number. Add those values up, and then subtract two for each initial 4.

### Example

Here’s an example. There is one 16 tile, two 8 tiles, and four 4 tiles, for a total of $$48 + 2 \times 8 + 4 \times 4 = 96$$ points. The actual score at this point was 84, and $$96 – 84 = 12$$, so there were three initial 4 tiles.

To get the initial 2 tiles, add up the actual tile values shown and divide by two. $$16 \times 1 + 8 \times 2 + 4 \times 4 + 2 \times 4 = 56$$ and $$56 \div 2 = 28$$. We determined that there were three initial 4 tiles; subtract two for each of these. That gives us $$28 – 3 \times 2 = 22$$.

That means that, if the grid shown has a score of 84 points, there were three initial 4 tiles and twenty-two initial 2 tiles. Hence, 12% of the time, the program creates a 4 tile.

### Win!

Here’s a second example, where we’ve won the game.

The maximum score is 20480 + 48 + 16 + 8 = 20552. The actual score was 20168, giving us a difference of 384. That means that 96 of the initial tiles were 4s.

The total for the visible tiles is 2088; dividing by two gives us 1044. $$1044 – 2 \times 96 = 852$$, the number of initial 2s. In this case, 10% of the initial tiles were 4s.

Clio Corvid

This site uses Akismet to reduce spam. Learn how your comment data is processed.