R-mahjong Ⅰ: break hand into sets

R-mahjong Ⅰ: break hand into sets

Undefined
DE English FR PL RU UK ZH-HANS

This mission is the beginning of a series of missions dedicated to Japanese game "riichi mahjong". In each subsequent mission, your task will become more difficult.

The meaning of riichi mahjong is to collect a certain combination of cards by discarding and taking cards. In this it resembles poker, only there are much more cards in it, and the rounds are longer. The cards in this game are called tiles, and each player has 14 of them.

In riichi, tiles come in five suits. Three of them are digital: man, pin and so; each of the digital suits contains tiles from 1 to 9. The fourth suit is dragons; it includes three types of tiles — a white dragon, a red dragon and a green dragon. The fifth is the wind. As it is easy to guess, it contains four winds according to the names of the cardinal directions. Each tile comes in four copies.

Now let's agree on the tile designations. The suits of man, pin and so will be abbreviated as "m", "p" and "s", and dragons and winds as "d", "w". Red, white and green dragons will be denoted by "r", "w" and "g". The "north", "south", etc. winds are encrypted in the same way as the cardinal directions. Thus, for example, "6 man" is written as "m6", and "green dragon" is written as "dg".

The finished hand should, as already mentioned, contain a certain combination of tiles. More precisely, it should contain four sets and a pair. There are two types of sets — chi and pona. Chi is a sequence of three tiles of the same suit in a row, for example: "m123" or "p567". In this case, combinations of the type "m912" are not allowed. Pons are three identical tiles of the same suit, that is, "s999" or "p444". A pair is two identical tiles.

Example of a hand: 234678 man, 234 pin, 888 so, two south winds. This hand contains four sets (234 pin, 234 man, 678 man chi; 888 so— pont) and a pair (two south winds). This will be encoded as "m2", "m3", "m4", "m6", "m7", "m8", "p2", "p3", "p4", "s8", "s8", "s8", "ws", "ws".

The goal of the mission is to split this set of tiles ("hand") into sets.

Input data: One argument (list type) is strings encoding tiles, in any order.

Output data: List of strings-sets (sorted).

Example:

riichi_mahjong_sets(['m2', 's9', 'p9', 'dg', 's3', 's2', 'm1', 's8', 'dg', 'p9', 'dg', 's7', 's1', 'm3']) == ['dggg', 'm123', 'p99', 's123', 's789']
Settings
Code:
Other:
Invalid hot key. Each hot key should be unique and valid
Hot keys:
CheckiO Extensions

CheckiO Extensions allow you to use local files to solve missions. More info in a blog post.

In order to install CheckiO client you'll need installed Python (version at least 3.8)

Install CheckiO Client first:

pip3 install checkio_client

Configure your tool

checkio --domain=py config --key=

Sync solutions into your local folder

checkio sync

(in beta testing) Launch local server so your browser can use it and sync solution between local file end extension on the fly. (doesn't work for safari)

checkio serv -d

Alternatevly, you can install Chrome extension or FF addon

checkio install-plugin
checkio install-plugin --ff
checkio install-plugin --chromium

Read more here about other functionality that the checkio client provides. Feel free to submit an issue in case of any difficulties.

Pair Programming (Beta-version)

Welcome to Pair Programming! Engage in real-time collaboration on coding projects by starting a session and sharing the provided unique URL with friends or colleagues. This feature is perfect for joint project development, debugging, or learning new skills together. Simply click 'Start Session' to begin your collaborative coding journey!

Waiting for Pair Programming to start...

You are trying to join a pair programming session that has not started yet.

Please wait for the session creator to join.

Waiting for Pair Programming to reconnect...

It looks like the creator of the pair programming session closed the editor window.

It might happen accidentally, so that you can wait for reconnection.

×
 
 
<< <
> >>
exec show

Whats Next?

Free accounts will see Best CheckiO solutions with some delay.
Best Solutions will be opened in a moment
Become Awesome and Don't wait
The next stage is ""
Will be activated in
View More Solutions Random Review Solutions Go to the next mission