
Obfuscating Python - shakna
https://gist.github.com/shakna-israel/03172c2c06e1f6622764541dc8b4246b#file-prose-md
======
Someone
FTA:

    
    
      > def _(n):
      >   if n <= 0:
      >     return n
      >   else:
      >     return (_(n - 1) + _(n - 2))
      > 
      > for i in range(0, 20):
      >   print(_(i))
    

> It's fairly simple and recognisable code. A simple recursive algorithm for
> printing the first 20 Fibonacci numbers.

That’s obfuscated enough to confuse the author; that program doesn’t print the
first 20 Fibonacci numbers, but their negatives :-)

Some simple fixes:

\- change line 2 to " _if n <= 1:_"

\- change line 3 to " _return -n_ ”

The obfuscated version ([https://gist.githubusercontent.com/shakna-
israel/03172c2c06e...](https://gist.githubusercontent.com/shakna-
israel/03172c2c06e1f6622764541dc8b4246b/raw/2d1258e1ea8d25786fc092c3728884e149e937d0/obfuscated.py)),
for me, is worse. It prints

    
    
      -3
      -4
      -7
      -11
      …
    

(tried both _python 2.7.16_ and _python3 3.7.4_ )

~~~
shakna
Darn, but I thought that might happen - it's why I laid out each of the
individual pieces you need to construct the final function first.

I probably replaced a magic number instead of the 2 in _(n - 2), from memory.
My editor was starting to have a panic attack trying to trace definitions when
I was finishing it.

