
Let’s look at a couple of examples how that can be done.įor Boolean values X and Y, the andoperator can be simply replaced with the bitwise & that will do the job just fine: print() #21 CharsĬomparisons can also sometimes be merged to get rid of the and operator(s): print() #19 Chars
#Golf with your friends cheat code#
When it comes to logic operators and code golf, a good rule of thumb to shorten your (Python) code is to try to get rid of as many and operators as possible.

The example above can be put into one line like this: print() 😉 ConditionalsĪ good place to start looking for those pesky characters that should be removed: the if statements and their lengthy conditions: if X and Y:įirst and most important thing here is realizing that if and else statements take up a lot of space but are rarely needed. Whether it’s a shortest Clash of Code, a CodinGame golf puzzle or a hole on Code-Golf.io, there’s always an unnecessary character or two hiding in your code. The following cheat sheet with the most used code golf tricks is aimed at both newbies looking to improve their golfing skills and veterans who want to make sure they know all the tricks in the book. As a result, Python, being as popular as it is, is the perfect language to try golfing an exercise or two and getting to experience competitive programming in a brand new way. With the CodinGame platform supporting only the conventional languages, Python is among the best golfing languages available, being slightly more verbose than Perl, Ruby or Bash. No matter the views, code golf is a way to learn something new about a language that you’ve already been familiar with for a long time. While some shake their head in disbelief whilst looking at golfed code, others shed a tear of joy after managing to get rid of another letter in their already cramped code. From people willing to learn all the ins and outs of a programming language to people wanting to put their esoteric language skills to use – code golf has always been the type of competition to attract a variety of programmers.
