A higher resolution is required to access the IDE
- 65
Learning Opportunities
This puzzle can be solved using the following concepts. Practice using these concepts and improve your skills.
Statement
Goal
2048:2048 is game played on a 4 by 4 grid. You start with
When moving tiles in a direction, if 2 adjacent tiles of the same value come in contact, they get merged into 1 tile, with value = 2*value of old tile. When 2 tiles merge, the user’s score increases by the value of the new tile.This way, you can keep increasing the value of a tile. At the end of each turn, the randomly generated tile can only have value =
--------------------------------------------------- xxx ---------------------------------------------------
The Problem:
Given a 2048 grid and the number of 4s generated, you have to output the player’s score and the number of turns played.
--------------------------------------------------- xxx ---------------------------------------------------
Example:
Consider the following game:
0 0 0 04s generated =
0 2 4 0
0 0 0 0
0 0 0 0
turns played =
USER moves DOWN
Grid becomes:
0 0 0 04s generated =
0 0 0 0
0 0 0 0
2 2 4 0
turns played =
score =
newly created tile =
USER moves LEFT
Grid becomes:
0 0 0 04s generated =
0 4 0 0
0 0 0 0
4 4 0 0
turns played =
score =
newly created tile =
So, given the following input:
0 0 0 0Your program must output:
0 4 0 0
0 0 0 0
4 4 0 0
2
4 2
--------------------------------------------------- xxx ---------------------------------------------------
The Game:
Play the game from the link:
Input
First 4 Lines: 4 space-separated integers CNT, the value of the current tile
Next Line: An integer FOURS, the number of 4s generated
Next Line: An integer FOURS, the number of 4s generated
Output
Line 1: An integer SCORE, the score of the user
Line 2: An integer TURNS, the number of turns played
Line 2: An integer TURNS, the number of turns played
Constraints
0 ≤ CNT ≤ 2³¹
Example
Input
0 0 0 0 0 4 0 0 0 0 0 0 4 4 0 0 2
Output
4 2
A higher resolution is required to access the IDE