Chris decided to code a game called 4096 which he believes is the next big thing. The game is relatively simple. You have a grid that contains integers that are all powers of 2. Tiles slide as far as possible in the chosen direction until they are stopped by either another tile or the edge of the grid. If two tiles of the same number collide while moving, they will merge into a tile with the total value of the two tiles that collided. The resulting tile cannot merge with another tile again in the same move.
The possible moves are which means swipe to the left, right, up and down respectively. Eventually, there will be some random number pops out and might replace the old tile.
Here is your starting configuration,
Wikipedia
This file contains 1000 lines. Each lines is an operation either :
L
: swipe to the left
R
: swipe to the right
U
: swipe up
D
: swipe down
P x y v
: replace cell
with number
. It is guaranteed that
is a power of 2.
What is the sum of all numbers in the grid after all operations are executed?
Details and Assumptions
The top row from left to right are cells .
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
Relevant wiki: Graph implementation and representation
2048 is a game invented by Gabriele Cirulli. Playing the game itself is simple, but coding it up is not. I often hear non-programmers under appreciate the effort of game and software developers. This inspires me to create this example problem. Sure, it does not need advanced algorithm and data structure, but the patience to code a seemingly tedious program neatly and provide high readability is often what programmer deals with. If you think this is tough, note that this problem does not fully simulate the game as I can "replace" tiles but the tiles appear on the game must be on an empty one. We still have a long way to code to its perfect form.
I admit this is not a neat code. It's just a lot of copy/paste and stress tested.