Mahjong is a tabletop game played using tiles. It features three "number" suits (pins, sous, mans, represented as
m) from 1 to 9, and one "honor" suit
z of seven distinct tiles. Note that contrary to western card games, tiles are not unique.
To complete a hand and win, the 13 tiles in your hand are combined with 1 newly drawn tile and must result in one of the following winning configurations:
- 4 sets and 1 pair, self-explanatory
- seven pairs, where all pairs are distinct (twice the same pair wouldn't qualify)
- kokushi musou: one of each of the 1 and 9 of each number suit, one of every seven honors, the remaining tile forming a pair (e.g.
A pair is any of the two same tiles:
A set consists of 3 tiles of the same suit. It can either be a run: 3 number tiles (p, s or m) in a connected run like
234s, but not
1m 2p 3s or
234z; or a triplet of any suit, not necessarily numbers, like
So honor tiles (non-numbers, represented by
z) can only form pairs or triplets, but not runs.
567z is not a set,
555z is a valid set,
55z is a valid pair.
A single tile can only be counted as part of one set or pair: there is no sharing or reusing.
Given a sorted hand of 13 tiles and one tile, check whether the 14 tiles make up a completed hand.
Input & Output
- You are given a sequence of numbers and letters, a space, then a tile of a number and a letter
1if the set is a match, else
- You are allowed to input the sequence and tile+letter as a list/array
222888m444p2277z 7z 234m45789p45688s 6p 11m4477p8899s116z 6z 19m19p19s1234567z 6z 123345567789m3p 3p
1122335778899m 1m 888m55s11222333z 4z 234m2233445566p 4p 19m139p19s123567z 4z 11m4477p8899s666z 6z
Credits to Unihedron for the puzzle!
This is code-golf, so shortest code wins!