Cody

# Problem 2265. 2048 Next Move

Solution 2971840

Submitted on 20 Sep 2020 by Ebrahim Mahmoud
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

### Test Suite

Test Status Code Input and Output
1   Pass
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 ]; assert(isequal(nextMove(board,dir),newBoard))

board = 0 0 0 2 0 0 4 4 0 0 0 16 0 0 0 16 board = 0 0 0 2 0 0 4 4 0 0 0 16 0 0 0 16 board = 0 0 0 2 0 0 4 4 0 0 0 32 0 0 0 0 board = 0 0 4 2 0 0 0 4 0 0 0 32 0 0 0 0 board = 0 0 4 2 0 0 0 4 0 0 0 32 0 0 0 0 board = 0 0 4 2 0 0 0 4 0 0 0 32 0 0 0 0 board = 0 0 4 2 0 0 0 4 0 0 0 32 0 0 0 0 board = 0 0 4 2 0 0 0 4 0 0 0 32 0 0 0 0 board = 0 0 4 2 0 0 0 4 0 0 0 32 0 0 0 0 board = 0 0 4 2 0 0 0 4 0 0 0 32 0 0 0 0 board = 0 0 4 2 0 0 0 4 0 0 0 32 0 0 0 0 board = 0 0 4 2 0 0 0 4 0 0 0 32 0 0 0 0 newBoard = 0 0 4 2 0 0 0 4 0 0 0 32 0 0 0 0

2   Pass
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 ]; assert(isequal(nextMove(board,dir),newBoard))

board = 4 32 0 0 128 4 0 2 2 16 8 0 0 0 0 0 board = 4 32 0 0 128 4 0 2 2 16 8 0 0 0 0 0 board = 4 32 0 0 128 4 0 2 2 16 8 0 0 0 0 0 board = 4 32 0 2 128 4 0 0 2 16 8 0 0 0 0 0 board = 4 32 0 2 128 4 8 0 2 16 0 0 0 0 0 0 board = 4 32 0 2 128 4 8 0 2 16 0 0 0 0 0 0 board = 4 32 8 2 128 4 0 0 2 16 0 0 0 0 0 0 board = 4 32 8 2 128 4 0 0 2 16 0 0 0 0 0 0 board = 4 32 8 2 128 4 0 0 2 16 0 0 0 0 0 0 board = 4 32 8 2 128 4 0 0 2 16 0 0 0 0 0 0 board = 4 32 8 2 128 4 0 0 2 16 0 0 0 0 0 0 board = 4 32 8 2 128 4 0 0 2 16 0 0 0 0 0 0 newBoard = 0 2 128 4 0 16 4 32 0 0 0 8 0 0 0 2

3   Pass
board = [ ... 0 8 0 4 2 64 16 2 2 8 8 16 4 2 2 4 ]; dir = 'left'; newBoard = [ ... 8 4 0 0 2 64 16 2 2 16 16 0 4 4 4 0 ]; assert(isequal(nextMove(board,dir),newBoard))

board = 4 2 2 0 2 8 64 8 2 8 16 0 4 16 2 4 board = 4 2 2 0 4 16 64 8 0 0 16 0 4 16 2 4 board = 4 2 2 0 4 16 64 8 0 0 16 0 4 16 2 4 board = 4 2 2 8 4 16 64 0 0 0 16 0 4 16 2 4 board = 4 2 2 8 4 16 64 0 0 0 16 0 4 16 2 4 board = 4 2 2 8 4 16 64 0 4 16 16 4 0 0 2 0 board = 4 2 2 8 4 16 64 0 4 16 16 4 0 0 2 0 board = 4 2 2 8 4 16 64 4 4 16 16 0 0 0 2 0 board = 4 2 2 8 4 16 64 4 4 16 16 0 0 0 2 0 board = 4 2 2 8 4 16 64 4 4 16 16 0 0 0 2 0 board = 4 2 2 8 4 16 64 4 4 16 16 0 0 0 2 0 board = 4 2 2 8 4 16 64 4 4 16 16 0 0 0 2 0 newBoard = 8 4 0 0 2 64 16 2 2 16 16 0 4 4 4 0

4   Pass
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 ] assert(isequal(nextMove(board,dir),newBoard))

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 board = 0 4 8 0 0 0 0 4 0 2 4 4 0 2 0 4 board = 0 4 8 0 0 0 0 8 0 2 4 0 0 2 0 4 board = 0 4 8 0 0 0 0 8 0 4 4 0 0 0 0 4 board = 0 4 8 8 0 0 0 0 0 4 4 0 0 0 0 4 board = 0 4 8 8 0 4 4 0 0 0 0 0 0 0 0 4 board = 0 4 8 8 0 4 4 0 0 0 0 4 0 0 0 0 board = 0 4 8 8 0 4 4 0 0 0 0 4 0 0 0 0 board = 0 4 8 8 0 4 4 4 0 0 0 0 0 0 0 0 board = 0 4 8 8 0 4 4 4 0 0 0 0 0 0 0 0 board = 0 4 8 8 0 4 4 4 0 0 0 0 0 0 0 0 board = 0 4 8 8 0 4 4 4 0 0 0 0 0 0 0 0 board = 0 4 8 8 0 4 4 4 0 0 0 0 0 0 0 0 newBoard = 8 4 0 0 8 4 0 0 4 4 0 0 0 0 0 0

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!