6 kyu

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: 1p 2p 3p 4p 5p 6p 7p 8p 9p
Bamboo: 1s 2s 3s 4s 5s 6s 7s 8s 9s
Characters: 1m 2m 3m 4m 5m 6m 7m 8m 9m

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
1z 2z 3z 4z
Red Dragon Green Dragon White Dragon
5z 6z 7z

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
2p 2p 2p 2s 3s 4s

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:

2p 3p 4p
└────┴────┘

meld 1

5s 6s 7s
└────┴────┘

meld 2

1m 2m 3m
└────┴────┘

meld 3

7m 7m 7m
└────┴────┘

meld 4

7z 7z
└───┘

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
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.
    "1p 1p 1p 2p 3p 4p 5p 6p 7p 8p 9p 9p 9p 9p"
    
    The order of the Mahjong pieces always be: p-->s-->m-->z and 1--->9

Output

  • A boolean value. If the input string is a valid winning hand of "JIU LIAN BAO DENG", return true; If not, return false.

Series

Puzzles
Games
Regular Expressions

Stats:

CreatedJul 10, 2016
PublishedJul 11, 2016
Warriors Trained270
Total Skips108
Total Code Submissions213
Total Times Completed36
JavaScript Completions36
Total Stars3
% of votes with a positive feedback rating86% of 18
Total "Very Satisfied" Votes15
Total "Somewhat Satisfied" Votes1
Total "Not Satisfied" Votes2
Total Rank Assessments3
Average Assessed Rank
6 kyu
Highest Assessed Rank
6 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • myjinxin2015 Avatar
  • kazk Avatar
  • Voile Avatar
Ad