“Code shortening” is the “sport” where participants strive to achieve the shortest possible source code that solves a programming problem by exploiting all the tricks and quirks of the language.
The SIZECON problem on SPOJ is one of the oldest and most popular code shortening problems on the web with a bizarre twist, only character above ASCII value 32 are counted for the penalty. During the talk we will take a journey into some frightening depths of the Python language in order to write shorter and shorter solutions to SIZECON until, exploiting a number of mind-blowing tricks, we will reach the current record solution for Python 3 of 31 characters.
I promise I’ll show you the most obfuscated, contrived and sick python code you have ever seen and (hopefully!) will ever see. I invite participants to give SIZECON a try and check their score against the Python3 rankings.
SPOJ is a coding platform and an online judge:
SIZECON is a unusual "code golf" problem:
* as long as you forget the bizarre ASCII special characters exception.
We can use as many ASCII special characters as we like...
Code legal characters
We can use as many ASCII special characters as we like...
String literal legal characters
Algorithm building blocks:
exec(ASCII32_decrypt('{encrypted_source_code}'))
exec('{source_code}')
ASCII32_encrypt('{source_code}')) -> '{encrypted_source_code}'
What we want
it get as input a string full with ASCII control characters
it outputs a string of python code
il must be short!
str.translate(table)
Return a copy of the string where all characters [...] have been mapped through the given translation table, which must be a string of length 256.
exec("{encrypted_source_code}".translate("{decrypt_table}"))
Same problem as SIZECON, but the score is the number of "different" characters with ASCII > 32.
Python interpreter: decrypts the ASCII32_encrypt'ed string
exec level 1: decrypts the number_encrypt'ed string
exec level 2: finally runs the solution