Problem 2265. 2048 Next Move
Given a board in the game 2048 (see the game here: 2048) and a direction ('up','down','left', or 'right'), move the game forward one turn.
Move and merge blocks as required by the game's rules, but for simplicity do not insert a new 2.
Example 1
board = [ ... 0 0 0 2 0 0 4 4 0 0 0 16 0 0 0 16] dir = 'up' newBoard = [ ... 0 0 4 2 0 0 0 4 0 0 0 32 0 0 0 0 ]
Example 2
board = [ ... 0 2 128 4 0 16 4 32 0 8 0 0 0 0 2 0 ] dir = 'right' newBoard = [ ... 0 2 128 4 0 16 4 32 0 0 0 8 0 0 0 2 ]
Example 3. Resolving Ambiguity
If we think of the directions as defining the pull of gravity, then we resolve ambiguous cases by first merging the two "lowest" blocks. See below.
board = [ ... 0 4 4 4 4 4 4 0 2 2 2 2 0 0 0 0 ] dir = 'left' newBoard = [ ... 8 4 0 0 8 4 0 0 4 4 0 0 0 0 0 0 ]
Inspired by a suggestion from Nick Howe.
Solution Stats
Problem Comments
-
12 Comments
You are welcome. I wouldn't probably notice it if I had not sent an incorrect submission.
6 players like this wonderful problem. But at the same time 6 players like a problem like Problem 43033. Create a constant offset.
This is very confusing ...
I would love to find a way to get people "liking" problems more often. Liking makes the author feel good about a job well done, but more importantly it points people to good problems. Sometimes we try to motivate people to like problems. This happened with the October triathlon contest (when the problem you reference was created). But it can have an unintended outcome of encouraging people to like problems that aren't that great. The results are very uneven. Bottom line: if you like a problem, please "like" it!
Solution Comments
Show commentsGroup

KR SA Joint & Collaborative Cody Event
- 35 Problems
- 2 Finishers
- Convert from Fahrenheit to Celsius
- Area of an equilateral triangle
- Find the sum of all the numbers of the input vector
- Function composition
- Sunday bonus
- Sum of odd numbers in a matrix
- Find the position of first minimum value in an integer array with numbers
- Sum of first n positive integers
- Determinant of a 3x3 Matrix
- Draw a '0' in a one matrix!
- Mersenne Primes
- Select every other element of a vector
- Find a Pythagorean triple
- Is this triangle right-angled?
- ~~~~~~~ WAVE ~~~~~~~~~
- Create an n-by-n null matrix and fill with ones certain positions
- Find max
- Calculate the derivative of a polynomial
- Extract part elements of matrix into one new matrix
- Triangle sequence
- 2048 Next Move
- Which doors are open?
- matrix zigzag
- Which values occur exactly three times?
- Binary numbers
- Counting Money
- Shuffle
- With apologies to William Blake
- MatCAT - Reconstruct X from Its X-rays
- Solve an ODE: equation B
- Longest run of consecutive numbers
- Vector push
- Five-dimensional maze
- The sliding puzzle: 3D
- One track five lanes
Problem Recent Solvers89
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!