[Community Puzzle] 2048 scores

Sorry if this question has been posted elsewhere, but I’m working on a functional approach to the 2048 Scores puzzle (https://www.codingame.com/training/medium/2048-scores). I’m pretty much done with the logic but upon testing I am failing the basic tests even though my output should be correct.

When I output the correct answer the tests say they found “Nothing”.

I tried hardcoding the answer, but when I do that it changes the answer it’s expecting to an incorrect answer. Really not sure why it’s behaving this way, but I’d love a little advice.Thanks!

Which language? Have you tried to compile/run your code locally? Are you sure to understand how the I/O of your language work (the simplest explanation to a failing hardcoded solution is that something is not printed correctly)?

Thanks for the reply. I’m using javascript, and yes it works locally when run through a node terminal.
For the first test case hardcoding console.log(“2”), results in a failure (found “2”, expecting “4”). Hardcoding console.log(“4”) also results in a failure (found Nothing, expecting “2”), even though the output is clearly displayed in the terminal.

Well, the expected output (to the example) is:

4
2

and the following hardcoded solution passes:

console.log("4\n2");
2 Likes

Ahh, I’m dumb! Totally missed the turns output parameter requirement. Feels bad.

Thank you for the help!

I have problem with understanding the 2048 scores puzzle “No hard coding!” test. I can not understand how the presented result has been achieved. The test case is following:

0 0 0 0
0 0 0 0
0 0 2 131072
0 0 0 0

Obviously the 2 tile has appeared during the last move. 131072 on the rightmost edge means that the player must have played the “RIGHT” move.

Preceding state could be one of the following:
0 0 0 0
0 0 0 0
131072 0 0 0
0 0 0 0

0 0 0 0
0 0 0 0
0 0 65536 65536
0 0 0 0

0 0 0 0
0 0 0 0
65536 65536 0 0
0 0 0 0

But the preceding state should contain tiles 2 or 4, because those tiles are generated on every move. I do not understand how the player could have played the game and arrived at this state.

1 Like

You’re right, but I don’t think the puzzle is meant to be realistic. In this scenario the goal is to find how many turns it would take to create a 131072 using the rules of 2048, and how much points you would have gained along the way.

2 Likes

Thanks Djoums, I believe your insight is correct :slight_smile: I derived the simple formula to calculate the game points, but I still fail to understand how to calculate the number of moves when there are no possible moves to get to the given game state. I must be overlooking something, because clearly there are players who have completed this puzzle.

Think about how many tiles you need to create another one, you can get insight from this.
For example an 8 would need two 4 to be merged, and each of them would need two 2 to be merged. Of course you start with some tiles and you get one each turn so you have to account for that too.