Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: (Golf) Mandelbrot Fractal

by japhy (Canon)
on May 08, 2002 at 16:30 UTC ( [id://165089]=note: print w/replies, xml ) Need Help??


in reply to (Golf) Mandelbrot Fractal

I cut it down to 153:
map{$i=$_*.05-1;map{$r=$j=$_*.05-2.3;$z=$i;$b=$";for (a..iv){$m=$r*$r;$n=$z*$z;$b="+",last if$m+$n>4;$z =2*$r*$z+$i;$r=$m-$n+$j}print$b}0..59;print$/}0..39
I think the for(a..iv) trick is a nice stroke-shaver.

_____________________________________________________
Jeff[japhy]Pinyan: Perl, regex, and perl hacker, who'd like a job (NYC-area)
s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;

Replies are listed 'Best First'.
Re: Re: (Golf) Mandelbrot Fractal
by pdcawley (Hermit) on May 08, 2002 at 17:51 UTC
    I'm sure there's more to come off, but I've worked it down to the following. Which seems to come in at 148 strokes using.
    -l map{$i=$_*.05-1;print map{$r=$j=$_*.05-2.3;$z=$i;$b=$";map{$m=$r*$r +;$n=$z*$z;$b='+'if$m+$n>4;$z=2*$r*$z+$i;$r=$m-$n+$j}a..iv;$b}0..59}0. +.39
      Application of YuckFoo's and my strategies gets us 134. There is an ever so slight change in the output due to the fudge factor introduced by YuckFoo's test change, switch back to the ()+() for 136 and no change in output.

      perl -l

      map{$i=$_/20-1;print map{$r=$j=$_/20-2.3;$z=$i;$b=$";map{$b='+'if $m=$r*$r,($n=$z*$z)>4;$z=2*$r*$z+$i;$r=$m-$n+$j}a..z;$b}0..59}0..39

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

      And, sticking with the principle that we must iterate as many times as the original and that the output must look the same I've stolen a few ideas from other code and come up with
      -l map{$i=$_/20-1;print map{$r=$;=$_/20;$z=$i;$b=$";($m=$r*$r)+($n=$z* +$z)>4?$b='+':($z=2*$r*$z+$i,$r=$m-$n+$;)for a..iv;$b}-46..13}0..39
      Which wc tells me is 136 chars long (counting 3 for "-l\n" in the same fashion as the perl.golf crowd). Having tried all the shorter solutions I've seen so far in this thread, I've not found one that actually works, but this one does.
        > I've not found one that actually works, but this one does
        It is afterall a fractal, and therefore only approximated at the horrendous resolution afforded by the dimensions selected. Whilte {NULE} gave a sepecific output to match, "gives a decent presentation of the Mandelbrot fractal" was also said which I believe warrants some artistic license.

        UPDATE: I did a little comparison between 165213 and the original output; after alignment, cropping and overlaying. The results are below. There are definitely differences; 88+33 out of 2440 to be exact

        overlay foo bar #X's are the golfed algorythm showing through. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++++++++++++++++++++++++++++++X+++++++++++++++ ++++++++++++++++++++++++++++++++++++++++++ X++++++++++++++ ++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++ ++++++++++++++++++++++++++++++++++++++++++ X++++++++++++++ ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++++++++++++++++++++++X++ X+++++++++++ +++++++++++++++++++++++++++++++++++ X+++++++ ++++++++++++++++++++++++++++++++++++ X+++++++ +++++++++++++++++++++++++++++++++++ ++++++++ ++++++++++++++++++++++++++++++++++ X+++++++ +++++++++++++++++++++++++++++++++ X+++++ +++++++++++++++++++++++++++++++++ X++++++ +++++++++++++++++++++++X+ +++++ X++++++ +++++++++++++++++++++++ X++ ++++++ ++++++++++++++++++++++ X+ ++++++ ++++++++++++++++++++++ + X++++++ ++++++++++++++++++++ + + X+++++++ ++++++ X++++++++ ++++++++++++++++++++ + + X+++++++ ++++++++++++++++++++++ + X++++++ ++++++++++++++++++++++ X+ ++++++ +++++++++++++++++++++++ X++ ++++++ +++++++++++++++++++++++X+ +++++ X++++++ +++++++++++++++++++++++++++++++++ X++++++ +++++++++++++++++++++++++++++++++ X+++++ ++++++++++++++++++++++++++++++++++ X+++++++ +++++++++++++++++++++++++++++++++++ ++++++++ ++++++++++++++++++++++++++++++++++++ X+++++++ +++++++++++++++++++++++++++++++++++ X+++++++ ++++++++++++++++++++++++++++++++++++X++ X+++++++++++ ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++++++++++++++++++++++++++++ X++++++++++++++ ++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++ ++++++++++++++++++++++++++++++++++++++++++ X++++++++++++++ ++++++++++++++++++++++++++++++++++++++++++++X+++++++++++++++ ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
        overlay bar foo #+'s are the original showing through. XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX+XXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX+XX+XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX+ XXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX+ XXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX+ XXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX+XX+X++++++X+X+XXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX++X++ XXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX+ XXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX++ XXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX+X+ XXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX+ XXXXX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X XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX+XXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

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

Re: Re: (Golf) Mandelbrot Fractal
by belg4mit (Prior) on May 08, 2002 at 18:06 UTC
    149 baby!
    map{$i=$_*.05-1;map{$r=$j=$_*.05-2.3;$z=$i;$b=$";for(a..iv){$m=$r*$r;$ +n=$z*$z; $m+$n>4?$b="+":($z=2*$r*$z+$i,$r=$m-$n+$j)}print$b}0..59;print$/}0..39

    148 for a tie

    map{$i=$_*.05-1;map{$r=$j=$_*.05-2.3;$z=$i;$b=$";for(a..iv){($m=$r*$r) ++ ($n=$z*$z)>4?$b="+":($z=2*$r*$z+$i,$r=$m-$n+$j)}print$b}0..59;print$/} +0..39

    Meanwhile, in the chatterbox...
    demerphq $i=$_*.05-1; could be written as $i=$_/2-1; couldnt it?
    belg4mit no, it's not .5
    belg4mit although /20 works ;-)

    146! @ Wed May 8 14:42:11 EDT 2002

    map{$i=$_/20-1;map{$r=$j=$_/20-2.3;$z=$i;$b=$";for(a..iv){($m=$r*$r)+ ($n=$z*$z)>4?$b="+":($z=2*$r*$z+$i,$r=$m-$n+$j)}print$b}0..59;print$/} +0..39

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

      In a wild attempt to redeem myself I get 142:

      UPDATE:Removed single line version cause it screws up some peoples screen layout.

      Or a little better formatted
      map{$i=$_/20-1;map{$r=$j=$_/20-2.3;$z=$i;$b=$";($m=$r*$r)+($n=$z*$z)>4 +? $b="+":($z=2*$r*$z+$i,$r=$m-$n+$j)for a..iv;print$b}0..59;print$/}0..3 +9

      Yves / DeMerphq
      ---
      Writing a good benchmark isnt as easy as it might look.

        Knock off a couple more. 26 iterations is plenty, so a..iv can be a..z. Also ($m=$r*$r)>4 is a sufficient test, so
        ($m=$r*$r)+($n=$z*$z)>4 #becomes: $n=$z*$z,($m=$r*$r)>4

        YuckFoo

        Update: Thanks belg4mit, changed semi-colon to comma to work in demerphq's code which becomes:

        map{$i=$_/20-1;map{$r=$j=$_/20-2.3;$z=$i;$b=$";$n=$z*$z,($m=$r*$r)>4 ?$b="+":($z=2*$r*$z+$i,$r=$m-$n+$j)for a..z;print$b}0..59;print$/}0..3 +9

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (2)
As of 2024-04-26 00:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found