#GYM104669I. 2048
2048
Description
Recently Bessie has gotten into the game 2048! The goal of 2048 is to create the number 2048 on a 4x4 grid by moving blocks left, right, up, and down. For example, if you move the blocks left, it will be as if you simulated gravity on the left side, with each block moving as far left as possible before colliding with another block. If 2 blocks are squished together and they have the same value, then they will combine to form 1 block that's double the value. After playing for many hours, Bessie has developed what she believes is the best strategy in the world, which is to go right, then go down, then repeat infinitely. However, using this strategy, the board will eventually become stuck. Given a 2048 board, print out the position in which the board gets stuck if Bessie uses her strategy. (Note that this isn't like actual 2048, where blocks will spawn after every move, so solve this problem as if no other blocks will be spawned in after every move. Also, note that even though sometimes going down or right might not change the grid, it is possible that the next right move may change the grid, in which you should continue the right down right down pattern).
In addition, note that on a single move, a block can't combine multiple times. For example, if you had the row $[2, 2, 2, 2]$, it would combine to form $[0, 0, 4, 4]$ rather than $[0, 0, 0, 8]$.
The blocks always merge with the rightmost/downmost blocks having greatest priority. For example the row $[0, 2, 2, 2]$ would merge into $[0, 0, 2, 4]$ rather than $[0, 0, 4, 2]$.
A 4x4 grid, with each position containing either a 0, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, or 2048, with the tiles separated by spaces as well. positions with a 0 should be considered blank spaces that aren't actual blocks.
Please output the final 4x4 grid where the grid will not change with any down or right movement.
Input
A 4x4 grid, with each position containing either a 0, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, or 2048, with the tiles separated by spaces as well. positions with a 0 should be considered blank spaces that aren't actual blocks.
Output
Please output the final 4x4 grid where the grid will not change with any down or right movement.
0 2 0 2
0 0 4 0
8 2 2 0
0 4 2 0
0 0 0 0
0 0 0 4
0 0 0 16
0 0 4 2