From c24da7cbbcd1a52720dd732f739c3e5b4724b2d1 Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Fri, 23 Sep 1994 14:08:41 +0000 Subject: Added obfuxcated lambda's by Ulf Bertelt --- Misc/FAQ | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/Misc/FAQ b/Misc/FAQ index e884fa9..43866d1 100644 --- a/Misc/FAQ +++ b/Misc/FAQ @@ -116,6 +116,7 @@ Here's an overview of the questions per chapter: ImportError: No module named ...; what gives? 4.11. Q. What GUI toolkits exist for Python? 4.12. Q. Are there any interfaces to commercial database in Python? + 4.13. Q. Is it possible to write obfuscated one-liners in Python? 5. Extending Python 5.1. Q. Can I create my own functions in C? @@ -683,6 +684,35 @@ A. There's an interface to SYBASE by John Redford There's also an interface to metalbase by Lance Ellinghouse . +4.13. Q. Is it possible to write obfuscated one-liners in Python? + +A. Yes. See the following three examples, due to Ulf Bartelt: + +# Primes < 1000 +print filter(None,map(lambda y:y*reduce(lambda x,y:x*y!=0,\ +map(lambda x,y=y:y%x,range(2,int(pow(y,0.5)+1))),1),range(2,1000))) + +# First 10 Fibonacci numbers +print map(lambda x,f=lambda x,f:(x<=1) or (f(x-1,f)+f(x-2,f)): f(x,f),\ +range(10)) + +# Mandelbrot set +print (lambda Ru,Ro,Iu,Io,IM,Sx,Sy:reduce(lambda x,y:x+y,map(lambda y,\ +Iu=Iu,Io=Io,Ru=Ru,Ro=Ro,Sy=Sy,L=lambda yc,Iu=Iu,Io=Io,Ru=Ru,Ro=Ro,i=IM,\ +Sx=Sx,Sy=Sy:reduce(lambda x,y:x+y,map(lambda x,xc=Ru,yc=yc,Ru=Ru,Ro=Ro,\ +i=i,Sx=Sx,F=lambda xc,yc,x,y,k,f=lambda xc,yc,x,y,k,f:(k<=0)or (x*x+y*y\ +>=4.0) or 1+f(xc,yc,x*x-y*y+xc,2.0*x*y+yc,k-1,f):f(xc,yc,x,y,k,f):chr(\ +64+F(Ru+x*(Ro-Ru)/Sx,yc,0,0,i)),range(Sx))):L(Iu+y*(Io-Iu)/Sy),range(Sy\ +))))(-2.1, 0.7, -1.2, 1.2, 30, 80, 24) +# \___ ___/ \___ ___/ | | |__ lines on screen +# V V | |______ columns on screen +# | | |__________ maximum of "iterations" +# | |_________________ range on y axis +# |____________________________ range on x axis + +Don't try this at home, kids! + + 5. Extending Python =================== -- cgit v0.12