Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
The verbiage in the description is misleading because you can't actually merge "one tile." A merge by definition requires combining more than one tile. BOTH tiles are merged into one. I believe the implicit meaning here is that a tile is said to be merged if and only if it is combined into the tile on the left, which is perfectly fine, but that’s not what merge means.
But either way, in the example, we merge the second 4 into the first, [4,4,8,16] --> [8,8,16,0], then merge the second 8 into the first [8,8,16,0] --> [16,16,0,0], and finally the second 16 into the first [16,16,0,0] --> [32,0,0,0].
Following that procedure for the test case, we merge the second 2 into the first, [2,0,2,4] --> [4,4,0,0], and then we should be able to merge the second 4 into the first. The right 4 was never merged with a tile, so why should it be excluded from performing a final merge? If we are able to slide the 16 to the left after each merge and then finally merge it at the end (as in the above example), why can’t we do that with the 4 here?
Enabled in this fork
This comment is hidden because it contains spoiler information about the solution
Added by Johan above
implemented for JS. Java could do with that as well; the instructions are very clear about returning a new array.
added. apologies for the delay. :P
Vulnerability for input mutation fixed.
Test for input mutation added.
Because the goal of our function is to implement "one swipe"(if this explanation makes the goal clearer):
A given tile can only merge once. (this limits any tile to be summed/combined only 1 time)
Your solution is mutating the input array and as a consequence, the tests are misbehaving. It is indeed a kata issue because the tests should not be vulnerable to this, but at the same time your solution is not exactly correct:
This comment is hidden because it contains spoiler information about the solution
Why isn't [2,0,2,4] == [8,0,0,0]?
Really tricky and puzzling kata to solve I'd say, compliments, I had a lot of fun with it.
Your kata was.... Unexplainably low for 6 kyu.
Good Job on making me cry solving this :)
This Kata had me hooked on the game for a while. :-D
Damn. Never reached 2048. I gave up crying.
so hard for 6kyu, but so interesting
Loading more items...