Skip to content

A suggestion on the mandelbrot one-liner in the docs FAQ #97709

@matheusja

Description

@matheusja

Documentation

On the docs FAQ there's a about obfuscated one-liners. The third one is a about the mandelbrot fractal, using the code:

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))

I suggest 2 changes:

  1. Replace reduce(lambda x, y: x+y, <...>) with ''.join(<...>)

  2. Make the outer join intersperse the lines with a newline character instead of relying on line wrapping. This will turn the outer ''.join(<...>) into '\n'.join(<...>)

This results on the following code:

print((lambda Ru,Ro,Iu,Io,IM,Sx,Sy:'\n'.join(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:''.join(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))

You can see the result and compare both on the following colab link: https://colab.research.google.com/drive/1NWfwNH_o5GPRTWwCdS-pVQLwEOSgstnz?usp=sharing

Metadata

Metadata

Assignees

No one assigned

    Labels

    docsDocumentation in the Doc dirsprint

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions