http://www.perlmonks.org?node_id=655046

Mandelbrot set inspired me to write my first obfu. I used the Hilbert Curve (as featured in XKCD). It takes an optional numeric argument on the command line (should be a positive integer less than ten, with a default of 5). There's no error checking on the argument, but the rest of the code is warningless under strict+warnings. I might write more about it when I need to procrastinate further. :-) Hint:

#!/usr/bin/perl use strict; use warnings; ;$ "=q%ef%;$_ =q~my($i,$ x,$y,$p)=( 0,0,0,pop| |5);my$r=2 << $p ;m y@ i= ma p[ (1 )x $r ,2 ],1..$ r;subi {$i[$x ][$y]- -}i;su bp{((1 <$_[0] ?$y:$x )- =1 -( $_ [0 ]&1)*2 ,i)for -1,1}s ubf{my ($ p,$f)= @_ ;$p--; my@m=( $f ,3 -$ f, 1- $f ); my @o =( 3- $f ,$ f, $f,$f-2)if $p>0;($_&= 3) for@o, @m;@o& &f ($p,pop@o) ,@ m& &p (pop@m )while(@o||@m) }f$p,( $p&1)* 2;subb {y ,y4102,b#\ n, ;p ri nt }m ap {b fo r@ $_ }@ i~;y~ \n~~d; ;s&b&b &g;$;= 1; eval;# %$ _+28;$ x-=$y; my ($ pi )= '3 .1 41 59 26535' ;$ ,= 2*2**$ [; ;my@b= map[5x $pi],1 ..$[;s {} {q %S {$ b[ $x ][ $y ]= 0} S; su bp {($_[0 ]>1?$y :$x+=- 1+$_[0 ]^2*2, S)for(0,1) }suba{($l, $d )=@_;$ l--;@m =map$_ *4,5-$ d,3-$d ,$d;@h=map $_*4,$d+2, $d ,$ d, 3- $d if $l >0 ;{ a( $l ,s hi ft @h)if@ h; @m &&p(sh if t@m);( @m+@h) &&redo }}a$l, $l ^2 *2 ;p ri nt @$ _,$/fo r@b($x ,$y,$c )=qw/0 0* /;$l=s hi ft||4; $r=$s* 2* *$ l; @b =m ap [( '' )x $r ], 1..$r; for(0,1){eval[ qw/$x- -$x++$ y--$y+ +/ ]->[i$_[0] ]; $b [$ x] [$y]=$c;}@ m=split//, [q w/rdll urdruu ld /]->[i$d]; @h =s pl it // ,[ qw /u ll dd rr ul uu rrddl/ ]->[i$ d]if$l >0;@m= sp lit//, {q w/lrdl rlurud ru du ld /} -> {$d};@ m=spli t//,su bstr'r dllurd ruuld' ,3*i$d ,3;@h= sp li t/ ,{ qw /l ul ld rd rr uu lu urdrddl/}- >{$d}if$l< 7;@m=split //,substr' ulldd'%}e;

Replies are listed 'Best First'.
Re: Hilbert Curve
by KurtSchwind (Chaplain) on Dec 05, 2007 at 12:54 UTC

    Nicely formatted!

    ++

    --
    I used to drive a Heisenbergmobile, but every time I looked at the speedometer, I got lost.

      Thanks. I just now managed to cut it down by quite a bit, but I think it looks too 'fat':

      #!/usr/bin/perl use strict; use warnings; ;$" =q%ef%;$_=q~my( $i,$x,$y,$p)=(0 ,0, 0,p op| |5) ;my $r= 2<< $p;my@i=m ap[(1)x$r ,2],1..$r ;subi{$i[ $x] [$y ]--}i;sub p{((1<$_[ 0]?$y:$x) -=1-($_[0 ]&1 )*2 ,i) for -1, 1}s ubf {my($p,$f)=@_;$ p--;my@m=($f,3- $f, 1-$ f); my@o=(3-$ f,$f,$f,$f-2)if$p>0;( $_&=3)for @o, @m; @o& &f( $p,pop@o) ,@m&&p(po p@m)while (@o||@m)} f$p ,($ p&1 )*2 ;su bb{y,y491 02, b#\ n,;print} map {bf or@ $_} @i~ ;y~ \n ~~d ;$; .=1;s&b&b &g;eval;# %$_+28;($ x-={}for@
        I think that is too obscure
Re: Hilbert Curve
by goibhniu (Hermit) on Dec 05, 2007 at 14:10 UTC

    Wonderful. Gotta love XKCD!

    I deparsed it adn pertidied it and it's still obfuscated - I'd say that's an additional ++ for an obfu post.


    I humbly seek wisdom.

      Thanks. I originally golfed it down while trying to use as few unique characters as possible. Fun 'vim' command du jour (use after you've selected some lines in Visual Line mode):

      :'<,'>!perl -lpwe '$h{$_}++for split//; END { print "\# $_ ", sprintf "\%02d", $h{$_} for grep /\S/, sort { $h{$a}<=>$h{$b} or $a cmp $b } keys \%h; }' | perl -pwe 'next unless/^\#/;$a||=$.-1;chomp;$_.=($.-$a)\%10?" ":"\n"'

      I may still write a variation that uses a different obfuscation method. (Anyone know of a golf competition that uses that metric [number of distinct chars.] as part of the score?) I think 30 was the lowest I managed while keeping it under 5 lines. (excluding the 'reŽxpanding and evaluating' code)

      $&(),-13;<=@[]_bfimnoprstuxy{}

      The alphabetics came from 'sub', 'print', 'pop', 'if', 'my', and the 'x' operator.

Re: Hilbert Curve
by Prof Vince (Friar) on Dec 08, 2007 at 12:18 UTC
    Nice obfu. Yet I hope you realize that this curve existed way before xkcd made it popular and that it has more to do than the sole geekish entertainment.

      Of course (hence 'featured', not 'introduced'). I'm guessing XKCD was not around in 1891. That's why I linked Wikipedia first. More info at the following excellent sites: Hilbert Curve at Mathworld and Peano Curve (more general) at PlanetMath.

      Update: Oops. Just looked at your profile, which states that you hate xkcd and wikipedia. Sorry for the salt in the wound.