6 kyu

Mahjong winning hand Validation #1: DA SI XI(大四喜)

54 of 58myjinxin2015

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: DA SI XI(大四喜,Four wind happiness).

Rules:

The combination of mahjong pieces must contains three 1z(east wind), three 2z(south wind), three 3z(west wind), three 4z(north wind)

1z 1z 1z 2z 2z 2z 3z 3z 3z 4z 4z 4z
 1z    1z    1z     2z    2z    2z      3z    3z    3z    4z    4z    4z

The rest pieces is a pair of any other pieces.

1m 1m

Input

  • A string denoting 14 tiles to be computed.
    "2s 2s 1z 1z 1z 2z 2z 2z 3z 3z 3z 4z 4z 4z"
    
    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 "DA SI XI", return true; If not, return false.

Series

Puzzles
Games
Regular Expressions

Stats:

CreatedJul 9, 2016
PublishedJul 9, 2016
Warriors Trained198
Total Skips30
Total Code Submissions169
Total Times Completed58
JavaScript Completions54
Python Completions8
Total Stars4
% of votes with a positive feedback rating95% of 29
Total "Very Satisfied" Votes26
Total "Somewhat Satisfied" Votes3
Total "Not Satisfied" Votes0
Total Rank Assessments4
Average Assessed Rank
6 kyu
Highest Assessed Rank
6 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • myjinxin2015 Avatar
  • kazk Avatar
  • Voile Avatar
  • dfhwze Avatar
  • phungj Avatar
Ad