Back
Close

Rummikub 2

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: Blue, Green, Red and Yellow. There are two tiles of each number-color combination. There are also Joker tiles, more on that below. Players play their tiles to form runs (same-colored uninterrupted range of numbers) or sets (same-numbered tiles all of a unique color). A valid run or set consists of at least three tiles, and a maximum of four (set) or thirteen (run). Example of a run: 3G 4G 5G 6G. Example of a set: 4B 4G 4R.

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:
TAKE tile rowid: take a tile from a row, or
PUT tile rowid: put a tile in a row, or
COMBINE rowid_1 rowid_2: combine two rows.

Apply the actions according to the following rules:
• Each TAKE action must always immediately be followed by a PUT action of the same tile. (While possible in the real game, in this puzzle you are not allowed to take another tile before putting away the already taken tile)
• After each PUT action, the table should only contain valid runs and/or sets.
• Your final action is always to PUT goalTile.
• A COMBINE action can be used to merge two runs into one longer valid run. Order the rowids from the two rows numerically. The new run gets the lowest rowid (rowid1), the other rowid (rowid2) becomes unused (and cannot be attributed to new runs).

You are allowed to split one valid run into two valid runs by a PUT or TAKE action. For example: TAKE the middle tile of a run of seven tiles, or PUT a tile in the middle of a run of five tiles. In case of a split, the new run with the highest numerical tile values gets a new rowid (highest rowid that ever existed + 1), and the other run keeps the original rowid.

Some examples of valid actions and their result on table rows:
Starting table
1 1G 2G 3G 4G
2 5G 6G 7G
3 4B 4R 4Y
ACTION 1: COMBINE 1 2 (This action creates a long run with lowest rowid1, higher rowid2 row is deleted)
Table after action 1:
1 1G 2G 3G 4G 5G 6G 7G
3 4B 4R 4Y
ACTION 2: TAKE 4G 1 (This action splits row 1; the run with highest numeric values gets a new rowid)
ACTION 3: PUT 4G 3 (A TAKE should directly be followed by a PUT)
Table after actions 2 and 3:
1 1G 2G 3G
3 4B 4G 4R 4Y
4 5G 6G 7G

Runs are always displayed from low to high value. Sets are always displayed in the order B G R Y.

Joker
In some cases, there can be a Joker (denoted as J) in a run or set. A joker can represent any number and color tile value. So, after a valid TAKE J rowid, the J can be added to any set or run that still has place. A joker is always displayed at the most right place (3R 4R J instead of J 3R 4R), except if it fills a space inside a run (3R J 5R). The actual value of J is never fixed (while displayed as 3R 4R J, it is not fixed whether J is 2R or 5R in this run; also, adding 5R to the run 3R 4R J 6R 7R does not split the run, since J is not fixed as 5R).

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. COMBINE always as early as possible;
3. COMBINE lower-numbered rowids before higher-numbered rowids (e.g. COMBINE 1 2 before COMBINE 1 3);
4. Never TAKE and/or PUT a J if it can also be done without;
5. If needed, TAKE and/or PUT a J as early as possible (but, if also rule 2 applies, COMBINE goes first).

Note
The real Rummikub allows for more complex actions (multiple TAKE after each other, after a single PUT the runs or sets do not need to be valid yet, as long as more PUTs are coming). To reduce difficulty of this puzzle, this is left out (the creator of the puzzle was not able to solve this).
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 by J), 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 a COMBINE action should be skipped.
Constraints
There is never more than 1 Joker.
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

Tags
SetsRecursionSimulation

Difficulty
Hard

Test cases
Multiple takes Test
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

Validator 1 Validator
Input
9R 5 1 8G 8R 8Y 2 7G 7R 7Y 3 6G 6R 6Y 4 3R 4R 5R 5 3B 4B 5B 6B 7B 8B
Output
TAKE 8B 5 PUT 8B 1 TAKE 7B 5 PUT 7B 2 TAKE 6B 5 PUT 6B 3 TAKE 6R 3 PUT 6R 4 TAKE 7R 2 PUT 7R 4 TAKE 8R 1 PUT 8R 4 PUT 9R 4 1 8B 8G 8Y 2 7B 7G 7Y 3 6B 6G 6Y 4 3R 4R 5R 6R 7R 8R 9R 5 3B 4B 5B

A lot of actions Test
Input
1G 10 1 3B 3G 3R 3Y 2 9B 9G 9R 9Y 3 7B 7G 7R 7Y 4 5B 5G 5R 5Y 5 4B 4G 4R 4Y 6 2B 2G 2R 2Y 7 8B 8G 8R 8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 PUT 6Y 16 TAKE 5Y 8 PUT 5Y 16 TAKE 4Y 2 PUT 4Y 16 TAKE 3Y 15 PUT 3Y 16 TAKE 2Y 3 PUT 2Y 16 PUT 1Y 16 1 6B 6G 6R 2 4B 4G 4R 3 2B 2G 2R 4 6G 7G 8G 5 10B 10G 10R 6 2G 3G 4G 5G 7 8B 8G 8R 8 5B 5G 5R 9 5R 6R 7R 8R 9R 10 9B 10B 11B 12B 11 9B 9G 9R 12 10R 11R 12R 13 7B 7G 7R 14 6B 7B 8B 15 3B 3G 3R 16 1Y 2Y 3Y 4Y 5Y 6Y 7Y 8Y 9Y 10Y 11Y 12Y 13Y

Joker Test
Input
8R 1 1 7R J 9R
Output
PUT 8R 1 1 7R 8R 9R J

Validator 6 Validator
Input
6G 1 1 5G J 7G
Output
PUT 6G 1 1 5G 6G 7G J

Joker in set Test
Input
13B 3 1 4G 4R J 2 1Y 2Y 3Y 4Y 5Y 6Y 7Y 3 9B 10B 11B
Output
TAKE 4Y 2 PUT 4Y 1 TAKE J 1 PUT J 3 PUT 13B 3 1 4G 4R 4Y 2 1Y 2Y 3Y 3 9B 10B 11B J 13B 4 5Y 6Y 7Y

Validator 7 Validator
Input
10Y 3 1 5G 5Y J 2 2B 3B 4B 5B 6B 7B 8B 3 6Y 7Y 8Y
Output
TAKE 5B 2 PUT 5B 1 TAKE J 1 PUT J 3 PUT 10Y 3 1 5B 5G 5Y 2 2B 3B 4B 3 6Y 7Y 8Y J 10Y 4 6B 7B 8B

Joker outside Test
Input
5B 2 1 4B 5B 6B 7B 2 6R 7R 8R J
Output
TAKE J 2 PUT J 1 PUT 5B 1 1 4B 5B J 2 6R 7R 8R 3 5B 6B 7B

Validator 8 Validator
Input
3B 2 1 2B 3B 4B 5B 2 4Y 5Y 6Y J
Output
TAKE J 2 PUT J 1 PUT 3B 1 1 2B 3B J 2 4Y 5Y 6Y 3 3B 4B 5B

Joker inside Test
Input
13R 4 1 9R 10R 11R 2 8B J 10B 3 5B 6B 7B 4 11B 12B 13B
Output
COMBINE 2 3 COMBINE 2 4 TAKE J 2 PUT J 1 PUT 13R 1 1 9R 10R 11R J 13R 2 5B 6B 7B 8B 5 10B 11B 12B 13B

Validator 9 Validator
Input
1R 4 1 3R 4R 5R 2 4B J 6B 3 7B 8B 9B 4 1B 2B 3B
Output
COMBINE 2 3 COMBINE 2 4 TAKE J 2 PUT J 1 PUT 1R 1 1 1R J 3R 4R 5R 2 1B 2B 3B 4B 5 6B 7B 8B 9B

Joke(r) Test
Input
7G 3 1 7B 7R 7Y 2 8B 9B 10B 11B J 3 3G 4G 5G
Output
PUT 7G 1 1 7B 7G 7R 7Y 2 8B 9B 10B 11B J 3 3G 4G 5G

Validator 10 Validator
Input
3G 3 1 8B 9B 10B 11B J 2 5G 6G 7G 3 3B 3R 3Y
Output
PUT 3G 3 1 8B 9B 10B 11B J 2 5G 6G 7G 3 3B 3G 3R 3Y

Don't use the joker Test
Input
5G 3 1 4Y 5Y 6Y J 2 6B 6G 6R 6Y 3 7G 8G 9G
Output
TAKE 6G 2 PUT 6G 3 PUT 5G 3 1 4Y 5Y 6Y J 2 6B 6R 6Y 3 5G 6G 7G 8G 9G

Validator 11 Validator
Input
8R 3 1 4R 5R 6R 2 4Y 5Y 6Y J 3 7B 7G 7R 7Y
Output
TAKE 7R 3 PUT 7R 1 PUT 8R 1 1 4R 5R 6R 7R 8R 2 4Y 5Y 6Y J 3 7B 7G 7Y

Get that joker Test
Input
3B 3 1 7R J 9R 2 8B 8G 8R 8Y 3 5B 6B 7B
Output
TAKE 8R 2 PUT 8R 1 TAKE J 1 PUT J 3 PUT 3B 3 1 7R 8R 9R 2 8B 8G 8Y 3 3B J 5B 6B 7B

Validator 12 Validator
Input
9Y 3 1 5B J 7B 2 6B 6G 6R 6Y 3 11Y 12Y 13Y
Output
TAKE 6B 2 PUT 6B 1 TAKE J 1 PUT J 3 PUT 9Y 3 1 5B 6B 7B 2 6G 6R 6Y 3 9Y J 11Y 12Y 13Y

Joker as early as poss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 4 2Y 3Y 4Y 5Y 6Y 5 11G 12G 13G 7 8B 8R 8Y 8 2G 3G 4G 9 8G 9G 10G

Joker combine Test
Input
3B 4 1 3R 4R J 2 5R 6R 7R 3 4B 4R 4Y 4 5B 6B 7B
Output
COMBINE 1 2 TAKE J 1 PUT J 4 PUT 3B 4 1 3R 4R 5R 6R 7R 3 4B 4R 4Y 4 3B J 5B 6B 7B

Validator 15 Validator
Input
5B 4 1 5R 6R J 2 7R 8R 9R 3 6B 6R 6Y 4 7B 8B 9B
Output
COMBINE 1 2 TAKE J 1 PUT J 4 PUT 5B 4 1 5R 6R 7R 8R 9R 3 6B 6R 6Y 4 5B J 7B 8B 9B

Multiple takes with J Test
Input
3G 5 1 4G 4R 4Y 2 6G 6R 6Y 3 4B 5B 6B 7B 8B 9B 4 7G 8G 9G 5 5R 5Y J
Output
TAKE 4B 3 PUT 4B 1 TAKE 5B 3 PUT 5B 5 TAKE J 5 PUT J 4 TAKE 6B 3 PUT 6B 2 TAKE 6G 2 PUT 6G 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 J 6G 7G 8G 9G 5 5B 5R 5Y

Validator 16 Validator
Input
9R 5 1 8G 8R 8Y 2 7G 7R 7Y 3 6G 6Y J 4 3R 4R 5R 5 3B 4B 5B 6B 7B 8B
Output
TAKE 8B 5 PUT 8B 1 TAKE 7B 5 PUT 7B 2 TAKE 6B 5 PUT 6B 3 TAKE J 3 PUT J 4 TAKE 7R 2 PUT 7R 4 TAKE 8R 1 PUT 8R 4 PUT 9R 4 1 8B 8G 8Y 2 7B 7G 7Y 3 6B 6G 6Y 4 3R 4R 5R J 7R 8R 9R 5 3B 4B 5B

A lot of actions with J Test
Input
1G 10 1 3B 3G 3R 3Y 2 9B 9G 9R 9Y 3 7B 7G 7R 7Y 4 5B 5G 5R 5Y 5 4B 4G 4R 4Y 6 2B 2G 2R 2Y 7 8B 8G 8R 8Y 8 6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9R 14 1Y 2Y 3Y 4Y 15 5Y 6Y J 8Y 16 10B 11B 12B 13B 17 10G 11G 12G 13G 18 10G 11G 12G 19 13B 13G 13Y 20 6Y 7Y 8Y

Validator 19 Validator
Input
8B 19 1 5B 5R 5Y 2 4G 5G 6G 3 6B 6R 6Y 4 7G 8G 9G 5 7R 8R 9R J 6 1B 1G 1R 1Y 7 7Y 8Y 9Y 8 2B 2G 2R 2Y 9 4B 4R 4Y 10 3B 3G 3R 3Y 11 10R 11R 12R 13R 12 13B 13G 13R 13 4Y 5Y 6Y 14 7Y 8Y 9Y 15 1B 2B 3B 4B 16 10Y 11Y 12Y 13Y 17 10G 11G 12G 13G 18 10R 11R 12R 19 5B 6B 7B 8B
Output
TAKE J 5 PUT J 19 TAKE 3G 10 PUT 3G 2 TAKE 6G 2 PUT 6G 3 TAKE 6B 3 PUT 6B 19 PUT 8B 19 1 5B 5R 5Y 2 3G 4G 5G 3 6G 6R 6Y 4 7G 8G 9G 5 7R 8R 9R 6 1B 1G 1R 1Y 7 7Y 8Y 9Y 8 2B 2G 2R 2Y 9 4B 4R 4Y 10 3B 3R 3Y 11 10R 11R 12R 13R 12 13B 13G 13R 13 4Y 5Y 6Y 14 7Y 8Y 9Y 15 1B 2B 3B 4B 16 10Y 11Y 12Y 13Y 17 10G 11G 12G 13G 18 10R 11R 12R 19 5B 6B J 8B 20 6B 7B 8B

Solution language

Solution

Stub generator input