Retired

Mahjong I: Is this a winning set? (retired)

6 of 7RedFog

Description:

Mahjong is an ancient game in China, which spreads all over the world. But how can we check if a set of tiles is a winning set?

To simplify the question, we assume that the tiles have only one suit. And we ignore the situation that it has chi-ed, pon-ed and kan-ed. You will get a string like "11122233344455" to describe a set of tiles. Your algorithm should return a boolean to tell if it's a winning set.

winning_set?('11122233344455') #-> true
winning_set?('11123456789999') #-> true
winning_set?('11223556677788') #-> false
winningSet [1,1,1,2,2,2,3,3,3,4,4,4,5,5] `shouldBe` True
winningSet [1,1,1,2,3,4,5,6,7,8,9,9,9,9] `shouldBe` True
winningSet [1,1,2,2,3,5,5,6,6,7,7,7,8,8] `shouldBe` False

Tips:

A set without chii, pon and kan will have exactly 14 tiles, and at most 4 of a kind.

Most of winning sets are like XXX-XXX-XXX-XXX-YY, in which XXX is ABC or AAA.

11122233344455 -> 111-222-333-444-55  
11123456789999 -> 123-456-789-999-11  

A special set of tiles is AABBCCDDEEFFGG means seven pairs, like 11224455667788. there should not be any same pairs in it (Japanese Mahjong rules).

Note: Four of a kind like AAAA can not appear in this special form.

Algorithms

Similar Kata:

More By Author:

Check out these other kata created by RedFog

Stats:

CreatedMar 31, 2016
Warriors Trained41
Total Skips11
Total Code Submissions91
Total Times Completed7
Ruby Completions6
Haskell Completions2
Total Stars1
% of votes with a positive feedback rating25% of 4
Total "Very Satisfied" Votes0
Total "Somewhat Satisfied" Votes2
Total "Not Satisfied" Votes2
Total Rank Assessments2
Average Assessed Rank
5 kyu
Highest Assessed Rank
5 kyu
Lowest Assessed Rank
6 kyu
Ad
Contributors
  • RedFog Avatar
  • jhoffner Avatar
  • Artoria Avatar
Ad