
Hello, checkiomates🐱👤!
This week's Python digest challenges you to refine your coding wisdom, starting with a critical look at design patterns that might hinder rather than help in Python. We then dive into the ubiquitous print() function, uncovering its full capabilities, and explore various strategies to truly speed up your Python code. For a mind-bending challenge, we present a mission to analyze a Pin Game board, tasking you with counting all possible valid moves from a given configuration.
💡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 nickname and then "Bookmarks". If you want to discover all CheckiO features, visit our tutorial. It's a longread, but it's worth it!
🏁 MISSION
Peg Jumping by freeman_lex -
The Pin Game is a puzzle that consists of a board with cross-shaped holes, initially filled with pins, except for an empty hole in the center. The goal is to perform valid movements to remove the pins until only one remains. You are given a board configuration as a list of 7 strings, each representing a line on the board. Your program should determine the number of possible valid moves.
peg_jump(["--.o.--", "--o.o--", "....o..", "....o..", "o.o.o..", "--o.o--", "--o.o--"]) == 2 peg_jump(["--ooo--", "--oo.--", "ooo.ooo", "oo...oo", "ooo.ooo", "--o.o--", "--ooo--"]) == 11 peg_jump(["--ooo--", "--oo.--", "oo.o.oo", "o..o..o", "oo.o.oo", "--oo.--", "--ooo--"]) == 8
📖 ARTICLES
Design Patterns You Should Unlearn in Python -
The Gang of Four design patterns specify object oriented solutions to common issues in code, except Python doesn’t have many of the problems the solutions are aiming to solve. This article talks about some of the common patterns and the easier ways to solve the problems they intend to address in Python.
Your Guide to the Python print() Function -
Learn how Python’s print() function works, avoid common pitfalls, and explore powerful alternatives and hidden features that can improve your code.
330× faster: Four different ways to speed up your code -
If your Python code is slow and needs to be fast, there are many different approaches you can take, from parallelism to writing a compiled extension. But if you just stick to one approach, it’s easy to miss potential speedups, and end up with code that is much slower than it could be.
👩💻CODE SHOT
What do you think the following code does?
def checkio(n: int) -> int: res = 1 for i in range(2, n + 1): res *= i return res
🙌 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! ⤵