A higher resolution is required to access the IDE
- 13
Learning Opportunities
This puzzle can be solved using the following concepts. Practice using these concepts and improve your skills.
Statement
Goal
This is part 1 of the two-part Rummikub puzzle. In this part, the basic dynamics are introduced.Rummikub is a game played with tiles numbered 1-13 in four colors:
You will get a table with valid runs and sets (rows), and one tile (goalTile) to put on the table in as few actions as possible. You must output all actions needed to put the tile on the table (becoming part of a valid run or set), and the new rows of the table after those actions.
Actions
One action can be one of:
•
•
•
Apply the actions according to the following rules:
• Each
• After each
• Your final action is always to
• A
You are allowed to split one valid run into two valid runs by a
Some examples of valid actions and their result on table rows:
Starting table
ACTION 1:
Table after action 1:
ACTION 2:
ACTION 3:
Table after actions 2 and 3:
Runs are always displayed from low to high value. Sets are always displayed in the order
Action selection and order
When different series of actions would lead to the same output, follow the rules below:
- Always select the least number of actions;
-
-
Note
The real Rummikub allows for more complex actions (multiple
Two important consequences of these rules (hint): 1) It is never possible to create a new set. It is only possible to make a set longer or shorter. 2) It is never possible to create a new run, except if it is created by splitting one run into multiple smaller valid runs.
Rummikub 2
Part two of the puzzle (https://www.codingame.com/training/hard/rummikub-2) follows the same rules, but adds the following:
- A
- Longer cases.
CREDITS to Cedricdd for coming up with several of the cases
Input
Line 1: string goalTile: tile to put on the table. A tile is a combination of a numeric value (1-13) and a single letter indicating the color (one of R , G , B or Y ) .
Line 2: integer nrow: number of rows (sets or runs) on the table.
Next nrow lines: row: the rowid (1-nrow), followed by space separated strings representing tiles, that form a valid run or set.
Line 2: integer nrow: number of rows (sets or runs) on the table.
Next nrow lines: row: the rowid (1-nrow), followed by space separated strings representing tiles, that form a valid run or set.
Output
naction lines: the actions needed to put goalTile on the table (one action per line), in the format: PUT tile rowid, TAKE tile rowid or COMBINE rowid1 rowid2.
nrow_new lines: the new rows that are formed after putting goalTile on the table (one row per line). The new rows have either their original rowid, or a new rowid (if it was a new row as a result from splitting an original row). Rows that became unused due to aCOMBINE action should be skipped.
nrow_new lines: the new rows that are formed after putting goalTile on the table (one row per line). The new rows have either their original rowid, or a new rowid (if it was a new row as a result from splitting an original row). Rows that became unused due to a
Constraints
Cases have been constructed such that there is always only one solution after following the action selection and order rules.
naction <= 7.
naction <= 7.
Example
Input
3R 2 1 4R 5R 6R 2 4B 4G 4Y
Output
PUT 3R 1 1 3R 4R 5R 6R 2 4B 4G 4Y
A higher resolution is required to access the IDE