A higher resolution is required to access the IDE
- 1
Learning Opportunities
This puzzle can be solved using the following concepts. Practice using these concepts and improve your skills.
Statement
Goal
This is part 2 of the two-part Rummikub puzzle. In part 1 (www.codingame.com/training/medium/rummikub-1), the basic dynamics are introduced. Part 2 works as a stand-alone puzzle, but for simpler examples it is advised to first solve part 1.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
Joker
In some cases, there can be a Joker (denoted as
Action selection and order
When different series of actions would lead to the same output, follow the rules below:
1. Always select the least number of actions;
2.
3.
4. Never
5. If needed,
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.
CREDITS to Cedricdd for coming up with several of the cases
Input
Line 1: string goalTile: non-Joker tile to put on the table. A non-Joker 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 (a non-Joker tile or a Joker tile, indicated byJ ), 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 (a non-Joker tile or a Joker tile, indicated by
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
There is never more than 1 J oker.
Cases have been constructed such that there is always only one solution after following the action selection and order rules.
Cases have been constructed such that there is always only one solution after following the action selection and order rules.
Example
Input
3G 5 1 4G 4R 4Y 2 6G 6R 6Y 3 4B 5B 6B 7B 8B 9B 4 7G 8G 9G 5 5G 5R 5Y
Output
TAKE 4B 3 PUT 4B 1 TAKE 5B 3 PUT 5B 5 TAKE 6B 3 PUT 6B 2 TAKE 6G 2 PUT 6G 4 TAKE 5G 5 PUT 5G 4 TAKE 4G 1 PUT 4G 4 PUT 3G 4 1 4B 4R 4Y 2 6B 6R 6Y 3 7B 8B 9B 4 3G 4G 5G 6G 7G 8G 9G 5 5B 5R 5Y
A higher resolution is required to access the IDE