Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: (Golf) Mandelbrot Fractal

by tadman (Prior)
on May 08, 2002 at 21:19 UTC ( [id://165186]=note: print w/replies, xml ) Need Help??


in reply to (Golf) Mandelbrot Fractal

Based on some musings in a deeper thread, a slight modification brings it to 131:
map{$i=$_/20-1;map{$r=$j=$_/20-2.3;$z=$i;($m=$r*$r,$n=$z*$z,$z=2*$r*$z+$i,$r=$m-$n+$j)for a..z;print$m<4?$":"+"}0..59;print$/}0..39
Update: With a bit of hackery then at 130:
map{$i=$_/20-1;map{$r=$j=$_/20-2.3;$z=$i;($n=$z*$z,$z=2*$r*$z+$i,$r=($m=$r*$r)-$n+$j)for a..z;print$m<4?$":"+"}0..59;print$/}0..39
As a note, using 'X' instead of '+' would save 2 characters.

If a slight readjustment of the newlines isn't invalid, you get 126:
print map{$i=$_/20-1;$/,map{$r=$j=$_/20-2.3;$z=$i;($n=$z*$z,$z=2*$r*$z+$i,$r=($m=$r*$r)-$n+$j)for a..z;$m<4?$":"+"}0..59}0..39

Replies are listed 'Best First'.
Re: Re: (Golf) Mandelbrot Fractal
by educated_foo (Vicar) on May 08, 2002 at 21:48 UTC
    125:
    -l map{$i=$_/20-1;print map{$r=$;=$_/20-2.3;$z=$i;$n=$z*$z,$m=$r*$r,$z +=2*$r*$z+$i,$r=$m-$n+$;for a..z;$m<4?$":"+"}0..59}0..39
    /s
    Update: 123
    -l map{$i=$_/20,print map{$r=$;=$_/20;$z=$i;$n=$z*$z,$m=$r*$r,$z=2*$r* +$z+$i,$r=$m-$n+$;for a..z;$m<4?$":"+"}-46..13}-20..19
      With some bending of the rules(?), we get a little more detail, and 117 chars

      perl -Mconstant=Z,20 -l map{$i=$_/Z,print map{$r=$;=$_/Z;$z=$i;$n=$z*$z,$m=$r*$r,$z=2*$r*$z+$i +,$r=$m-$n+$;for a..z;$m<4?$":"+"}-46..Z}-19..Z

      116 @ Wed May 8 19:50:10 EDT 2002

      map{$i=$_/Z,print map{$r=$;=$_/Z;$z=$i;$n=$z*$z,$z=2*$r*$z+$i,$r=($m=$ +r*$r)-$n+$;for a..z;$m<4?$":"+"}-46..Z}-19..Z

      BTW, I like the use of $; :-)

      UPDATE: Changed outside range from -20..Z to -19..Z to eliminate extra lines of +.

      --
      perl -pew "s/\b;([mnst])/'$1/g"

        Jesus christ ...

        But I think using the constant declaration on the outside is cheating. Hmm!


        --
        Ash OS durbatulk, ash OS gimbatul,
        Ash OS thrakatulk, agh burzum-ishi krimpatul!
        Uzg-Microsoft-ishi amal fauthut burguuli.

      That use of $; is very clever, as it parses correctly and allows you to omit the brackets for the for. Combining this with other modifications yields 122 chars of obfuscated goodness:
      print map{$i=$_/20;$/,map{$r=$;=$_/20;$z=$i;$n=$z*$z,$z=2*$r*$z+$i,$r=($m=$r*$r)-$n+$;for a..z;$m<4?$":"+"}-46..13}-20..19
      Further savings if you choose 'X' instead of '+':
      print map{$i=$_/20;$/,map{$r=$;=$_/20;$z=$i;$n=$z*$z,$z=2*$r*$z+$i,$r=($m=$r*$r)-$n+$;for a..z;$m<4?$":X}-46..13}-20..19
      Here is the original C code, just for comparison, at 182 characters:
      void main(){double O,x,o,I,l,i;char _;for(l=-1;l<1;l+=.05,putc ;i<.7;i+=.05,putchar(_?'?':':'),O=i,x=l,o=I=(_=1)--)for(;++_&& );x=2*O*x+l,O=o-I+i);}
      C allows for shorter variable names, and Perl still comes out ahead. Crazy.
        The only catch appears to be that, when I actually run this, it doesn't work. Of course, I could well be going mad.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://165186]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (3)
As of 2024-04-19 05:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found