Hello, checkiomates๐ฑโ๐ค!
This week, we improve your development skills by exploring techniques for debugging live Python code, boost your application speed with ten smart performance hacks, and test your foundational knowledge with a quiz on optional function arguments. Our mission challenges your algorithmic thinking to find the maximum capture sequence for a berserk chess rook against an enemy army.
๐กTIP
On Easy difficulty, each of the few starting stations is dedicated to a distinct data type. If you want to discover all CheckiO features, visit our tutorial. It's a longread, but it's worth it!
๐ MISSION
Berserk Rook by bryukh -
For this mission you have one berserk rook facing off against an army of enemy rooks. The berserk rook can only move if it will capture an enemy unit. So on each turn it will move and capture until there are no enemy targets left where it will take one "empty" step and stop. You are given the position of your berserk rook and the positions of the enemy rooks. Your goal is capture as many units as possible without stopping. Each move in your sequence should capture an enemy unit. The result will be the maximum possible number of enemy rooks captured.
berserk_rook(u'd3', {u'd6', u'b6', u'c8', u'g4', u'b8', u'g6'}) == 5
berserk_rook(u'a2', {u'f6', u'f2', u'a6', u'f8', u'h8', u'h6'}) == 6
berserk_rook(u'a2', {u'f6', u'f8', u'f2', u'a6', u'h6'}) == 4
๐ ARTICLES
Debugging live code with CPython 3.14 -
Python 3.14 added new capabilities to attach to and debug a running process. Learn what this means for debugging and examining your running code.
10 Smart Performance Hacks For Faster Python Code -
Some practical optimization hacks, from data structures to built-in modules, that boost speed, reduce overhead, and keep your Python code clean.
Using Python Optional Arguments When Defining Functions Quiz -
Practice Python function parameters, default values, args, *kwargs, and safe optional arguments with quick questions and short code tasks.
๐ฉโ๐ปCODE SHOT
What do you think the following code does?
def checkio(cmds: list[str], s=[]) -> int:
e, s = {"PU": lambda x: s.append(x.split()[1]) == 1,
"PO": lambda x: s.pop() if s else 0,
"PE": lambda x: s[len(s)-1] if s else 0}, []
return sum([int(e[x[:2]](x)) for x in cmds])
๐ 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! โคต
