3 ms·
Obfuscating Python
- Someone 7y agoFTA: > 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/03172c2c06e1f6622764541dc8b4246b/raw/2d1258e1ea8d25786fc092c3728884e149e937d0/obfuscated.py https://gist.githubusercontent.com/shakna-israel/03172c2c06e...), for me, is worse. It prints -3 -4 -7 -11 … (tried both python 2.7.16 and python3 3.7.4)
- shakna 7y agoDarn, 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.