Fun with lambda and map
ivo at nospamAmaze.nl
ivo at nospamAmaze.nl
Tue Feb 5 06:39:19 EST 2002
gbreed at cix.compulink.co.uk wrote:
: Gerson Kurz wrote:
:> If you're in a masochistic mood, you can write this in one line:
:>
:> fac = lambda n:map(lambda x:(map(lambda a:a and 1,[x[0]()])[0] and
:> x[1]()) or x[2](x[3]),[[lambda:not n,lambda:n==n,lambda
:> n:fac(n-1)*n,n]])[0]
: If you're allowing booleans and subtraction, how about
: fac = lambda x: not x or x*fac(x-1)
Well, I'm not allowing python operations, nor python numbers (the numbers
in the lambda system are presented as lambda's themselve, so a pythonic
'not' won't work on them. However, that could be fixed)
Ivo
--
Drs. I.R. van der Wijk -=-
Brouwersgracht 132 Amaze Internet Services V.O.F.
1013 HA Amsterdam -=-
Tel: +31-20-4688336 Linux/Web/Zope/SQL
Fax: +31-20-4688337 Network Solutions
Web: http://www.amaze.nl/ Consultancy
Email: ivo at nospamAmaze.nl -=-
More information about the Python-list
mailing list