Friday, 18 February 2022

Wordle, Nerdle and other dles

Edit: well I don't recommend people playing the original Wordle, which is now under NYT due to their hideous changes to the game, including banning words from dictionary, making answer words notoriously difficult, and ADDING AD TRACKERS ON THE GAME SITE

Although we won't possibly try Wordle anymore...the science behind the game is still fun to look into. There are also other interesting non-commercial variants like those I listed below. I hope you will spend a little time trying and feel fun about those :)

Recently it has became a trend to play Wordle or its variant: Nerdle, Kotobade Asobou, Primel,... and you can extend the list for another 10 or more games.


From a computational perspective, finding the optimal route is easy given the fixed dictionary set and the limited word length (5). Not necessarily the best but the entropy approach is classic (cf. strategies against games like hangman), efficient and near optimal. 3Blue1Brown made two very high quality videos (as usual) which you can find here and there.

The only thing to point out is that the overall efficiency (distribution on number of guesses) relies on how you weight the frequency/likelihood of those answer-words. It is fine not to assume anything (word frequency), but if any I would set the cut-off (the inflexion point for the sigmoid function) much much narrower given that most answer-words seems to be common enough, more common than the impression from the actual pool size (~2300 words). Of course the ideal weighting is to equate the frequency of occurrence for words as answer, but that would be a meta thing to consider after.

I have been using the same starter from day 1 -- POWER. Clearly not the most efficient as O and E are not the most popular vowels and W is fairly uncommon, but I feel like to stick with that and see how do I perform. So far so good: I averaged 3.6 guesses over the past games.

But English is never my specialty...it would be more interesting to talk about Nerdle, the one based on numbers and the four arithmetic operators. Mahjong Handle is also fun given its totally different nature and an essentially harder variant to tackle. 

Nerdle.


10 numbers, 4 operators and the equal sign, with 8 slots and 6 guesses. A much easier game given its highly predictable pattern (math based) and a small letter pool size. In fact there are two starters that covers all 15 letters that you can almost always guess it right on the third guess with some exception. 

The first exception comes from equivalence by operator inverses. For example 12/3 = 4 can be expressed as 4*3 = 12. Such equivalence can usually be eliminated once you know which operator appears and which does not.

The second exception comes from equivalence upon translation for + and -. For example 3+8=11 translates to 5+8=13. Again it can be eliminated by fully exhausting all 10 possible numbers with proper starters. (It is in fact possible for translation to happen using the same set of numbers. Can you find one? -- just keep reading if you can't :P)

The third exception is by commutativity. For example 6+9=15 swaps to 9+6=15, 12/3=4 swaps to 12/4=3 and so on. Unlike the previous two exceptions, the starters do not necessarily eliminate commutativity. In fact, the author of Nerdle said that it won't be fun without allowing commutativity...although he added the choice of playing the game that accepts equivalent commutated answer at the end. 

The strategy is simple from here: you use the two starters (in a very rare case if the first starter is good enough one may also give it a try). Once you know all the symbols appearing in the expression it should be easy to get the right answer in the third guess (upon commutativity). There many ways for one to eliminate most random permutations of letters:

- RHS is presumably a single number without operators. The equal sign should appear on the 5th-7th slot, which is then clear from the starters. That means the expression on the left consists of 4-6 letters with 1 or at most 2 operators. You can then guess the position of those operators before filling the numbers in.

- The possibility for RHS is greatly limited by the operators given. An expression with single digit numbers, + and - only would not exceed 19/29 and you know the 1 must be at the 6th slot (if ='s on the 5th). Checks like mod 10 are also very helpful.

Take Nerdle#20 as an example. The two starters told you that the letters are 1, 3, 5, 6, + and =; also = is at 6th with +, 1, 6, 5 not at 2nd, 3rd, 7th and 8th slot respectively. What's the correct answer?

With 5 slots on LHS and only + allowed the answer is either a sum of 3 single digit numbers or a sum of two double digits. Let's look at the possibility of a sum of three single digit numbers. Clearly RHS must be 1x: 11 and 13 are too small as 6+5+3=14; 15 is not allowed and the only combination that sums to 16 is 6+5+5 where 3 is missing. 

What about a sum of two double digits? By checking mod 10 the possibilities for the ones are 1+5=3+3=6, 5+6=11 and nothing else. Notice that the tens on RHS is not 6 but it's not 11 either, so we need an extra 10 from the ones meaning that the ones must be 5 and 6. We now look for combinations that add to 2, 4 or 5 (so that the corresponding tens would be 3, 5 or 6). The possibilities are 1+1=2 and 1+3=4.

Plugging in we conclude that we have two distinct expressions satisfying the hints from the two starters: 15+16=31 and 15+36=51. One of them would be the third guess and if that fails we know for sure what's the right answer at the fourth guess even without commutativity (why?).

*

The phenomenon of "when your first serious attempt (for the right answer) failed you can easily give the correct answer right away" is important because not only that the chance of getting right is respectable, but it is also informative for you to get the right answer even if it doesn't work. In that way we have largely avoided the long tail cases (guessing 5+ times) and compresses the average number of guesses required  to the minimum. But what about games where long tail cases are well possible?

Welcome to the world of Mahjong Handle, where you guess a given valid hand in 6 guesses. 

*I never play Mahjong in English and I guess that applies to most of you guys...check Wiki if you are not sure about the terminology.

How hard is Mahjong Handle? We start by counting the number of valid winning hands in Japanese mahjong. I am sure there is a calculated number somewhere on the web, but to make it simpler we consider a very restricted yaku type -- all triplet hand (対々和) where you need 4 triplets and a pair. Simple math tells you that there are C(36,4)*32 = 1884960 ways to score an all triplet hand and that is already 1000 times as massive as Wordle's answer pool! There is no doubt that the actual number of valid hands is at least 20 times larger...or 50 times, 100 times maybe?

With that in mind, exhaustive information theory approach isn't practical anymore (another differences between Wordle and Mahjong Handle is that frequency analysis doesn't work here -- at least there is no obvious frequency references). Even if one managed to estimate the information provided by each guesses one must face the long tail problem. Unlike Nerdle, it may take up to 2 extra necessary guesses. Given the overall complexity of the game it often decides whether one gets it within 6 guesses or not. 

To give a more solid example one may consider the combination 2223334 and you are waiting for one extra tile. The extra tile can be 2, 3 or 4:

2: 222 234 33
3: 22 234 333
4: 222 333 44

While you may not know anything about whether it's 2, 3 or 4 in previous guesses. Things can be taken to extreme in the case of nine gates(九蓮宝燈) where all nine tiles are possible in the case of 11123456778999.

Gathering information on appearance is cheap, but information on repetition is expensive because it takes up multiple slots. It's even more expensive to ask if a tile appears 3 or 4 times, yet it's always possible given that triplet is a basic block in the hand. 

As a consequence we often fall into a long tail trap where the remaining uncertainty is low, but each guess would only help by a little. The simple greedy approach as in the video (entropy + probability) may not work very well, but I bet that a secondary correction would help greatly (note: 3Blue1Brown also mentioned this in his second video).

The real challenge is to evaluate each pieces of information gathered from the guesses though. Since exhaustive evaluation is now impossible, we can instead assign weightings to different kinds of partial information regarding the building block of 3 or 2. Rating from the least to the most useful information:

- a given tile is not in the hand
- a given tile is in a hand
- a tile is in a hand and is isolated from the sides
- a tile is in a given block
- a tile is in a block of sequences
- a sequence block with 2 known tiles
- a fully known sequence block
- a fully known triplet block
- a fully known block and isolated from the sides
...

Of course there are technical problems where blocks are often ambiguous when they stick together, but the idea should be clear: we assign weightings to each categories of information and play Mahjong handle prioritizing guesses according to the  weightings assigned. We then adjust weightings to improve  efficiency. No optimal performance guaranteed (as for any non-convex optimization), but it should be good enough.

And for humans like us how do we tackle the game?

Well I don't have any concrete suggestions even for starters. Thirteen orphans(国士無双) is certainly something to start with, but some says that these terminal tiles do not actually appear in hands *that* often comparing to the simple 13/36 coverage. Some also suggests the use of seven pairs due to its flexibility and to detect repetition but some also say that to be a waste. Some prefer to use loads of sequences...it's hard to tell which one's the best but I ended up using thirteen orphans as my starter. There are two reasons for that:

1) Coverage is still important. It is still very probable for at least one of the 13 tiles to appear in the hand and this is the cheapest way to ask for all 13 of them in one go.

2) Detecting honor tiles are very costly. In normal hands you need 2 or 3 copies of an honor tile for the hand to be valid, but for thirteen orphans you only need a single copy of it. This is another long tail problem -- any of the seven honor tiles may appear in your hand. Any algorithm that neglects them will face the chance of wasting 2 or 3 extra guesses at the end just to detect them. 

After that it's also about detecting sequences and repetitions. When both terminals (1,9) are void from the hand you can detect any sequence with 3 tiles (456), although repetition of 2, 3, 6 and 7 will be harder to detect. Some would prefer the use of two sequences (e.g. 234+678) to avoid that. Which is the better approach? I can't really tell.

For Wordle and Nerdle, one starts making reasonable attempt at guess number 3, but for Mahjong handle the guess should start no earlier than the fourth guess. From here you can really pile up something close to the answer and complete the final pieces using the ordering hints. There are too many 'rules' to apply and I can't even count them all, but here is one for example: if you have two consecutive tiles (e.g 56s) one labelled orange and one labelled blue then these two tiles must be a repetition of the tile labelled blue (why?).

Still getting it right on the fifth guess is not that easy and here is my stats:

There are definitely better strats as observed from the daily performance of my friends, but I enjoyed more the later guesses for this game and haven't bothered to optimize the overall approach (yet). If you have any ideas please comment and tell me that :D

Tuesday, 4 January 2022

04/01/2022: 聽說afk回來會變強

 
快……快了 (話說不是Senpuu嗎w)


新年快樂。

又一年新年在疫情的陰影下度過,以致我根本沒有甚麼好寫。總不能寫我抽不到門票進C99吧?不過至少最底限度的新年儀式都有辦妥:做紅豆湯(本來要做糕點的但是電子磅壞掉了)、看紅白、看箱根駅伝。本來以為今年會是戰國時代,沒想到青學還是太強了,連半點機會也沒給其他學校。就算駒澤的ace沒爆掉也不可能追上11分鐘的差距吧?

來說一下我好久沒提過的音遊好了。說好久沒提過,其實因為某些原因下半年都沒玩過,不過現在又重新打起來了。主要原因大概是要DDR當成做運動……吧?聽說音遊玩家afk一段時間後回鍋會變強,今天來驗證一下在我身上是否成立好了。

DDR:體力沒大退化,平時在家裡也有玩健身環/Jump rope challenge(其實是跑步)。爆發力在家裡練不了但退步不明顯,至少瓶頸還是在BPM 200 (Pluto relinquish, Anti-matter之類)。比較大的問題是讀譜真的退步了:以前習慣打450-480 Boost,BPM 200可以調到500 Boost正常打,Neutrino爆發段可以調到600 Boost;現在比較舒服的是420-460 Boost,500 Boost會非常不舒服,600 Boost打Neutrino CSP完全看不清。另一個讀譜的問題是看不懂比較複雜的連打比如A4A CSP慢速段和Possession (20th anniversary mix) CSP的地雷段。當然這些以前多半也只是半懂,但現在是看到直接石化的感覺。現在重新每週兩次每次打七道,希望能慢慢回復。

太鼓:很神奇地我重新打街機太鼓了。對上一次有常規打街機太鼓的時候熊蜂飛行還是10星……現在打回去感覺上肢耐力比以前好,大概因為有玩健身環。不過最神奇的是我好像突然就適應半~全換了!這對於以前街機用炒菜而Osu用三指的我來說是從來沒試過的東西,只能說是日有所思夜有所夢就悟出來了吧。

以前我街機可以打大部分9星和幾首10星……現在也是,不過是現在的9星和10星。以前第一首過的10星是mint tears,到了2022第一首過的10星也還是mint tears--我覺得這首快要被降格就是。主要瓶頸還是在體力和速度上,看多練一段時間會不會變好吧。

Nos:沒練。感覺打完太鼓手就沒力彈琴了,明明打下去miss比以前還要少(所以afk一段時間真的會變不同),但用疲憊的雙手彈下去完全沒了那種優雅的感覺,也就漸漸不想打了。另外感覺難度漲的很快,最近也沒有很驚艷的歌曲(除了スーパー戦湯ババンバーン和bemani symphony系列--沒想到Nagiha居然投身K社),根本沒有每週四衝下去解歌的動力。

喔對了,看過紅白我才發現まふまふ這傢伙也太帥,根本是從FF7裡走出來的吧?歌唱力也沒話說,完爆那個炒解散話題的Bish。所以那個Ado甚麼時候也要上紅白露一手?