Stupid ways to spell simple code

Joshua Landau joshua.landau.ws at gmail.com
Sun Jun 30 17:52:17 EDT 2013


On 30 June 2013 18:36, Steven D'Aprano
<steve+comp.lang.python at pearwood.info> wrote:
> Pfft! Where's the challenge in that? Let's use an O(n!) algorithm for
> sorting -- yes, n factorial -- AND abuse a generator expression for its
> side effect. As a bonus, we use itertools, and just for the lulz, I
> obfuscate as many of the names as I can:
>
>
> from random import shuffle as OOO00O
> from itertools import takewhile as OO0O0O, count as O0OO0O
>
> OO0O00 = range(5)
>
> list(OO0O0O(lambda O: any(O[O0] < O[O0-1] for O0 in
>     range(1, sum(('O' for O in O), type('O', (),
>     {'__add__': lambda O0O, OO0: OO0})()).count('O'))),
>     (OOO00O(OO0O00) or OO0O00 for O in O0OO0O())))[0]

I've got to say -- that last line got me for quite a while, especially
as the list of lists was returning a list of sorted lists!

For obfuscation, though, you want unicode. It's much harder to reason
about code that you can't read.

from itertools import count as æ, permutations as Æ, starmap as ð
[globals().setdefault("%c"%sum(ø.encode()),ß)for ø,ß in
vars(__builtins__).items()if ø!="vars"]
sorted = lambda ħ:ƿ(ƞ for ı in
φ(ƴ(lambda:ħ,æ),ń(0,ń(ħ)**(len(ħ)*2-1)*len(ħ)))for ƞ in Æ(ħ)if
ǂ(()).__eq__((ŕ(ð(ǂ(Ƽ(ƞ).pop()).__rpow__,φ(ŕ(œ(ƞ,ƴ(lambda:0,ħ)),()),1))),ħ),ı))[::-1]

print(sorted([4, -3, 4, 2, -1]))

This only works for integers (including negatives) and some things
that seem to do nothing but slow it down are needed to cover special
cases. This one takes about 3½ minutes on my computer -- it's got a
runtime efficiency of something along the lines of O( (L!) * ((L)**i)
)  for i being related to the elements in the list and L being the
length of the list.

That said, it's rather OK at sorting [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0].


I know this is more oriented towards obfuscation of code than
obfuscation of technique, but --as I said-- I'm writing a library for
that. I'll be back when it's ready.



More information about the Python-list mailing list