26
This is my first question here, so any suggestions in the comments would be appreciated! Thanks ;)
Introduction
One very common strategy for the 2048 game is never ever swiping down. This positions all the big numbers at the top, and the lower ones in the bottom. So, if you apply this strategy correctly, your board will always match the following pattern:
The pattern to check for / Your task
Your submission should be either a full program or a function which returns a truthy value if the board can be described like this: Going down each column of the board, the first number should be the highest of the column, the second number should be less than or equal to the first number, etc. A good 2048-board is defined as a board where the highest numbers are all on the top. This is code-golf, so the shortest Code per language (in bytes) wins.
I/O
The input can be taken in any appropriate way, for example an array of 4 arrays, each containing 4 numbers, or an array of 16 numbers. In total, it will be always 16 numbers, representing the 4x4 board The output should be a truthy value of the input is a "good 2048-board", and a falsy value otherwise.
Examples
Truthy:
|-------------------|
| 16 | | 64 | 8 |
|-------------------|
| 8 | | 32 | 8 |
|-------------------|
| 4 | | 32 | 2 |
|-------------------|
| 2 | | | |
|-------------------|
|-------------------|
| 16 | 128| 64 | 32 |
|-------------------|
| 8 | 128| 32 | 8 |
|-------------------|
| 4 | 16 | 8 | 2 |
|-------------------|
| 4 | | | |
|-------------------|
Falsy:
|-------------------|
| 16 | | 64 | 8 |
|-------------------|
| 8 | | 32 | 16 |
|-------------------|
| 32 | | 128| 2 |
|-------------------|
| 2 | | | |
|-------------------|
|-------------------|
| 16 | 128| 64 | 32 |
|-------------------|
| 8 | 32| | 8 |
|-------------------|
| 4 | 16 | 8 | 2 |
|-------------------|
| 4 | | | |
|-------------------|
Note
Look at the 2nd falsy test case: When there is an empty value (or a 0) somewhere and even when it's followed by a value which is higher than the last non-zero number, this should be falsy, because the next value after the zero would be higher than the 0 itself, which makes it invalid.
Good luck!
Comments are not for extended discussion; this conversation has been moved to chat.
– Martin Ender – 2017-09-03T13:14:44.483