Post image
Light Mode
Dark Mode
Python Polish, Developer Insights, and the Mahjong Enigma

Hello, checkiomates🐱‍👤!

Here's a look at what's in this week's Python digest: We explore practical tips for refactoring boolean expressions to write cleaner, more readable code and delve into insights on what distinguishes the "best" programmers in the field. Test your knowledge of a core Python feature with a quiz on set comprehensions. Capping it off is a particularly challenging mission involving the complexities of Riichi Mahjong, offering a unique puzzle to tackle.

💡TIP

If you find an interesting solution, you may add it to your bookmarks by clicking the flag near solution title. You can find all your bookmarked solutions by clicking your nickame and then "Bookmarks".
If you want to discover all CheckiO features, visit our tutorial. It's a longread, but it's worth it!

🏁 MISSION

R-mahjong ⅠⅠⅠ: count shanten by gleb10101010101 -

This is the third mission in the series about the game riichi mahjong. This mission is more difficult than the previous ones, so be prepared. This time, your task is to determine which is the smallest number of tiles in the hand you need to replace in order to make it a winning one. In other words, it is necessary to determine its so-called shanten number. Remember that there is not only the standard "four sets and a pair" hand pattern, but also chitoitsu and kokushi-muso. For simplicity, the possibility of open sets is omitted. However, you should thoroughly check the input data and, if it is invalid, return None.

riichi_mahjong_shanten(['p4', 'p5', 'p6', 'm1', 'm1', 'm1', 's2', 's3', 's4', 's5', 'we', 'we', 'dw', 'dw']) == 1

📖 ARTICLES

Refactoring long Boolean expressions -

This article shows you how you can improve the readability of long boolean expressions by splitting your code, naming sub-expressions, or rewriting your Boolean logic.

The Best Programmers I Know -

In this opinion piece, the author writes about the traits he thinks make a good developer. They include things like reading the docs, knowing your tools, continuous learning, helping others, and more.

Python Set Comprehensions: How and When to Use Them Quiz -

Set comprehensions are a concise and quick way to create, transform, and filter sets in Python. They can significantly enhance your code’s conciseness and readability compared to using regular for loops to process your sets.

👩‍💻CODE SHOT

How do you think, what the following code does?

from typing import Iterable

def ?????????(items: list) -> Iterable:

    it = iter(sorted(e for e in items if e))

    yield from [next(it) if e else 0 for e in items]

🙌 Thanks for your attention! Hope to meet you at CheckiO, as well as at our Instagram and Twitter! We are really interested in your thoughts! Please, leave a comment below! ⤵

Created: April 22, 2025, 4:09 p.m.
0
40
User avatar
freeman_lex