← Back to challenges

Mahjong Tiles

PythonHardarraysgamesloops

Instructions

Your goal is to create a function that returns a list with a string for each of the 108 tiles in the following format:

"rank suit"

Where rank is a number from 1 to 9 and suit is one of the three suits (tong, tiao, wan), both written in the pinyin transcription of Mandarin Chinese (for numbers see table below).

NumberCharacterPinyin
1yi
2er
3san
4si
5wu
6liu
7qi
8ba
9jiu

Three of the tiles have special names. Each of the 4 copies of these tiles should be represented by their names only (no suit, no rank):

  • One of tong is called bing gan (饼干, cookie)
  • Two of tong is called yan jing (眼镜, glasses)
  • One of tiao is called ji (鸡, chicken)

Examples of tiles

Five of tong ➞ "wu tong"

Seven of wan ➞ "qi wan"

One of tiao ➞ "ji"

Three of tiao ➞ "san tiao"

Notes

  • Don't forget to include 4 copies of each tile.
  • Don't forget to substitute the tiles with special names.
  • You can return the tiles in any order.
python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.