Beta

Mahjong - #3 How far from winning

Description:

Mahjong Series

(If you do not know about how to win the game, click here for reference.)

Each player is dealt a hand of random tiles at the start of each Mahjong game. Sakura gets addictive to the game. After playing a few games, she learns that it is easier to win starting with a good hand, while harder starting with a bad one. Therefore, Sakura wonders how difficult it is to win with a certain hand. Now, she turns to you, an intelligent coder, for help.

Task

Given a hand of 14 tiles, work out the minimum number of tiles required to replace, for making up a winning hand. Only regular winning hands are considered in this kata.

  • Input

    • A string denoting 14 tiles to be computed, in the order of Circles ([1-9]p), Bamboo ([1-9]s), Characters ([1-9]m), and Honors ([1-7]z). The tiles are space-separated.
  • Output

    • An integer.

Example

"3p 5p 2s 3s 4s 5s 5s 6m 8m 3z 3z 5z 6z 7z" => 3
  One possible replacement:
  ("5z 6z 7z" -> "4p 7m 3z")
"3p 4p 5p 5p 5p 1s 2s 2s 3s 3s 4s 4z 4z 4z" => 0
  Already winning. No need to replace any of the tiles.
Games
Logic
Algorithms

Stats:

CreatedJul 4, 2016
PublishedJul 4, 2016
Warriors Trained56
Total Skips1
Total Code Submissions84
Total Times Completed8
JavaScript Completions8
Total Stars4
% of votes with a positive feedback rating100% of 1
Total "Very Satisfied" Votes1
Total "Somewhat Satisfied" Votes0
Total "Not Satisfied" Votes0
Ad
Contributors
  • Hacker Sakana Avatar
Ad