A friend of mine sent me a link to a discussion of obfuscating code in C. In this particular discussion the programmer attacked a simple terminal application which produced a Mandelbrot fractal. It's a rather impressive bit of C coding (to a less than adept C coder), but I thought it would be fun to attack in Perl. (Note: I can't get the C code to compile on gcc, but I didn't try very hard.)
The C code example is 189 characters (my count with removed whitespace). I consider this more a golf than obfuscation since obfuscation implies a deliberate attempt to mislead the reader. The intent here was merely to make it as small as possible, and in the process it became difficult to read.
My code in Perl is 164 characters (less the shebang and newlines). This is my first official golf, so I'm sure someone out there will outdo me. I'd love to see it, and it might be fun to let the author of the C article see what madness we come up with.
This outputs a 60 column by 40 row graph of ' ' and '+' which gives a decent presentation of the Mandelbrot fractal. Read the original article for more information. It was tested on Solaris 2.8 with Perl 5.005_3 and 5.6.1, but should run anywhere.#! /usr/bin/perl for(0..39){$i=-1+$_*.05;for(0..59){$r=$j=-2.3+$_*.05; $z=$i;$b=" ";for(0..255){$m=$r*$r;$n=$z*$z;if($m+$n>4) {$b="+";last}$z=2*$r*$z+$i;$r=$m-$n+$j}print$b}print"\n"}
Good luck!
{NULE}
--
http://www.nule.org
__END__ Output should be this: ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++ ++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++ ++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++ ++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++ ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++++++++++++++++++++++ ++ +++++++++++ +++++++++++++++++++++++++++++++++++ +++++++ ++++++++++++++++++++++++++++++++++++ +++++++ +++++++++++++++++++++++++++++++++++ ++++++++ ++++++++++++++++++++++++++++++++++ +++++++ +++++++++++++++++++++++++++++++++ +++++ +++++++++++++++++++++++++++++++++ ++++++ +++++++++++++++++++++++ + +++++ ++++++ +++++++++++++++++++++++ ++ ++++++ ++++++++++++++++++++++ + ++++++ ++++++++++++++++++++++ + ++++++ ++++++++++++++++++++ + + +++++++ ++++++ ++++++++ ++++++++++++++++++++ + + +++++++ ++++++++++++++++++++++ + ++++++ ++++++++++++++++++++++ + ++++++ +++++++++++++++++++++++ ++ ++++++ +++++++++++++++++++++++ + +++++ ++++++ +++++++++++++++++++++++++++++++++ ++++++ +++++++++++++++++++++++++++++++++ +++++ ++++++++++++++++++++++++++++++++++ +++++++ +++++++++++++++++++++++++++++++++++ ++++++++ ++++++++++++++++++++++++++++++++++++ +++++++ +++++++++++++++++++++++++++++++++++ +++++++ ++++++++++++++++++++++++++++++++++++ ++ +++++++++++ ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++ ++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++ ++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++ ++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++ ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: (Golf) Mandelbrot Fractal
by japhy (Canon) on May 08, 2002 at 16:30 UTC | |
by pdcawley (Hermit) on May 08, 2002 at 17:51 UTC | |
by belg4mit (Prior) on May 08, 2002 at 20:45 UTC | |
by pdcawley (Hermit) on May 09, 2002 at 08:51 UTC | |
by belg4mit (Prior) on May 09, 2002 at 12:26 UTC | |
by belg4mit (Prior) on May 08, 2002 at 18:06 UTC | |
by demerphq (Chancellor) on May 08, 2002 at 18:54 UTC | |
by YuckFoo (Abbot) on May 08, 2002 at 19:11 UTC | |
by belg4mit (Prior) on May 08, 2002 at 20:10 UTC | |
Re: (Golf) Mandelbrot Fractal
by {NULE} (Hermit) on May 08, 2002 at 16:07 UTC | |
Re: (Golf) Mandelbrot Fractal
by tadman (Prior) on May 08, 2002 at 21:19 UTC | |
by educated_foo (Vicar) on May 08, 2002 at 21:48 UTC | |
by belg4mit (Prior) on May 08, 2002 at 23:27 UTC | |
by hagus (Monk) on May 09, 2002 at 00:01 UTC | |
by educated_foo (Vicar) on May 09, 2002 at 00:34 UTC | |
by tadman (Prior) on May 09, 2002 at 00:51 UTC | |
by pdcawley (Hermit) on May 09, 2002 at 06:45 UTC | |
by tadman (Prior) on May 09, 2002 at 08:03 UTC | |
Re: (Golf) Mandelbrot Fractal
by YuckFoo (Abbot) on May 08, 2002 at 21:08 UTC | |
Re: (Golf) Mandelbrot Fractal
by {NULE} (Hermit) on May 10, 2002 at 12:57 UTC |