Mahjong winning hand Validation #4: JIU LIAN BAO DENG(九莲宝灯)
Description:
Mahjong Knowledge
Mahjong
is based on draw-and-discard card games that were popular in 18th and 19th century China and some are still popular today.
In each deck, there are three different suits numbered 1 to 9, which are called Simple tiles. They are Circles (denoted by [1-9]p
), Bamboo (denoted by [1-9]s
), and Characters (denoted by [1-9]m
).
Circles: |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Bamboo: |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Characters: |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Moreover, there is another suit named Honor tiles. It includes Wind tiles (namely East, South, West, North, denoted by [1-4]z
) and Dragon tiles (namely Red, Green, White, denoted by [5-7]z
).
East Wind | South Wind | West Wind | North Wind |
![]() |
![]() |
![]() |
![]() |
Red Dragon | Green Dragon | White Dragon |
![]() |
![]() |
![]() |
Note that there are EXACTLY 4 identical copies of each kind of tiles in a deck.
How to win the game of mahjong
A regular winning hand consists of 4 Melds and 1 Pair. Each meld of tiles can be 3 identical or consecutive tiles of a suit. For example:
3 identical tiles | 3 consecutive tiles |
![]() ![]() ![]() |
![]() ![]() ![]() |
Note that the Honor tiles ([1-7]z
, winds and dragons) can ONLY be combined to a meld of 3 identical tiles
.
A winning combination of mahjong pieces:
![]() ![]() ![]() └────┴────┘
meld 1 |
![]() ![]() ![]() └────┴────┘
meld 2 |
![]() ![]() ![]() └────┴────┘
meld 3 |
![]() ![]() ![]() └────┴────┘
meld 4 |
![]() ![]() └───┘
pair 1 |
Task
Your task is to verify that a mahjong combination is correct. The mahjong combination is: JIU LIAN BAO DENG(九莲宝灯, Win for 9 pieces).
Rules
All mahjong pieces must from a same suits(Circles([1-9]p
) or Bamboo ([1-9]s
or Characters ([1-9]m
)).
The basic body is 13 pieces:"1x 1x 1x 2x 3x 4x 5x 6x 7x 8x 9x 9x 9x", x
can replaced by p,s or m
. And then add any one of the same suit will be able to win (because no matter what number to add, mahjong can be divided into 4 melds and 1 pair).
An example of JIU LIAN BAO DENG using circles:
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
1p 1p 1p 2p 3p 4p 5p 6p 7p 8p 9p 9p 9p + 9p
divided into 4 melds and 1 pair:
1p1p 1p2p3p 4p5p6p 7p8p9p 9p9p9p
Input
- A string denoting 14 tiles to be computed.
The order of the Mahjong pieces always be:"1p 1p 1p 2p 3p 4p 5p 6p 7p 8p 9p 9p 9p 9p"
p-->s-->m-->z
and1--->9
Output
- A boolean value. If the input string is a valid winning hand of "JIU LIAN BAO DENG", return
true
; If not, returnfalse
.
Series
Similar Kata:
Stats:
Created | Jul 10, 2016 |
Published | Jul 11, 2016 |
Warriors Trained | 270 |
Total Skips | 108 |
Total Code Submissions | 213 |
Total Times Completed | 36 |
JavaScript Completions | 36 |
Total Stars | 3 |
% of votes with a positive feedback rating | 86% of 18 |
Total "Very Satisfied" Votes | 15 |
Total "Somewhat Satisfied" Votes | 1 |
Total "Not Satisfied" Votes | 2 |
Total Rank Assessments | 3 |
Average Assessed Rank | 6 kyu |
Highest Assessed Rank | 6 kyu |
Lowest Assessed Rank | 7 kyu |