# Mahjong and π

The first fourteen digits of π create a winning hand in almost every variant of mahjong. How often do random collections of digits form one? Are there any other famous ones?

This is a statement with a lot of context which is just long enough to fill a Gemini document. So let's do that.

# Breaking it down

The first fourteen digits of π after the decimal point are "14159 26535 8979". While I think everyone can either remember it or look it up, I should mention this here just so that we are clear that we mean that we ignore the integer part, 3.

A winning hand in mahjong, with some caveats, consists of four melds and a pair. This statement does not apply at all to American mahjong, which is very Galapagos in nature and has very different ways to form a hand. It also does not apply to the mahjong game where you click matching pairs of tiles and make them disappear, called "mahjong solitaire", which we will absolutely not discuss here because it's a completely different game, like Memory is to poker.

It also does not entirely apply to the rest, which have some special edge cases which we will also not go into as it is not relevant to the topic.

Mahjong Solitaire on Wikipedia

But what is a meld? A meld is any one of these things:

- Three number tiles with the same suit, such that they form consecutive numbers. For example, 🀛🀜🀝 or 🀙🀚🀛. The numbers must be consecutive.
- Three identical tiles, like 🀛🀛🀛 or 🀞🀞🀞 or even 🀀🀀🀀.
- Four identical tiles.

A pair of tiles means "two identical tiles". So like 🀞🀞.

What are the tiles then? They are either number tiles, wind tiles or dragons.

Wind tiles are these four: 🀀🀁🀂🀃. We will not use them in this discussion, but we include these for completeness.

Honour tiles are these three: 🀄︎🀅🀆. We will only use one of these, which we will get to later.

And number tiles are all the rest. They have a number associated with them, which is why they are called that. Think of them like playing cards with a rank and a suit. There are three suits and nine ranks. In this discussion we will only use one suit but they are interchangeable. Because not everyone knows Chinese I will choose the suit that requires the least amount of interpretation, which are these: 🀙🀚🀛🀜🀝🀞🀟🀠🀡. They represent the numbers 1 to 9.

There are four copies of each tile in every complete set of tiles. There are exceptions (which you must be tired of hearing by now) but again they are not relevant and we will ignore them.

The goal of a game of mahjong is to draw and discard tiles from a pool of tiles either discarded by someone else or from a fresh draw pile ("the wall") so that you can make a winning pattern. There are some limitations, sometimes, but all the hands we will discuss are always enough to win if you can form one.

# Putting it back together

Note that you can change the order of your tiles in any way to make it easy for you and your opponents to confirm that you have a winning hand.

So let's say you have the digits of π in your hand, as number tiles:

14159 26535 8979

🀙🀜🀙🀝🀡 🀚🀞🀝🀛🀝 🀠🀡🀟🀡

But we can rearrange them like this:

🀙🀙 🀚🀛🀜 🀝🀝🀝 🀞🀟🀠 🀡🀡🀡

Which are in fact the four melds and a pair that we want.

No official rules say that they are worth more because they form the digits of π. (They're already very valuable for reasons we won't get to, but you don't get bonus points for making them spell π.) But you can always add a house rule that says that if you have those tiles, you can win more points.

# But wait, there's more

Taiwanese mahjong is unlike all the rest in that it wants five melds and a pair for you to win. You start with sixteen tiles, so sometimes this is called "sixteen-tile Taiwanese mahjong".

The next three digits of π is 323, but it turns out that with a little bit of reshuffling you can make the requisite winning pattern:

🀙🀚🀛 🀙🀚🀛 🀛🀜🀝 🀝🀝 🀞🀟🀠 🀡🀡🀡

(But be aware that in some places, this will be displayed with no spaces and in sorted order, so it looks like this: 🀙🀙🀚🀚🀛🀛🀛🀜🀝🀝🀝🀞🀟🀠🀡🀡🀡. As order does not matter, this is the same hand.)

# So here are my questions

## Four melds and a pair

How many random collections of 14 ~ 18 digits can you make that are also winning hands? Notice that four identical tiles count as a single meld, so the number of tiles in a winning hand can actually vary. But remember there are only four copies of each tile.

## Five melds and a pair

If we include the Taiwanese game into our search space, the number of digits to span over go from 14 ~ 18 to 14 ~ 22. How many of those are winning hands?

## 🀆

You may have noticed that 0 is not included in the number tiles. The game never had tiles with rank 0, just like how playing cards don't have rank 0.

The Americans have our back here. Their winning hands sometimes include weird stuff that need zeros, and when they do they use the "soap" tile, 🀆, to represent the digit. It is properly called "the white dragon" because the actual tile is blank (though in most parts of the world the tile is actually a picture of a blank tile, not a blank tile, because of historical reasons) and so white (as the material of the tile is white), but the Americans call it "soap" because look at it.

(There is nothing particularly "dragon"-y about the tile; in Chinese it's not called a dragon, and this is a translation artefact from some entirely too excitable Euro-Americans when translating the game.)

But let's not go too wild. Although it looks like a 0, the white dragon is not a zero and therefore cannot form a sequence of tiles. The formal reason is because the white dragon does not have a rank and so its rank cannot be adjacent to anything. But it can form a triplet of identical tiles, 🀆🀆🀆, and all four can be collected into a single meld, 🀆🀆🀆🀆.

With this additional constraint, how many more sequences of digits of the right length can be winning tiles?

It's possible to make an exhaustive search or even just enumerate all the possible winning hands but I can't be bothered to right now.